0% found this document useful (0 votes)
37 views4 pages

Exp 3 Part 1

Uploaded by

ISHWAR CHAND
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views4 pages

Exp 3 Part 1

Uploaded by

ISHWAR CHAND
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL -3

3 (a) TITLE: CREATING TABLES, INSERT INTO TABLES & SELECT FROM TABLES

3.1 Objective 3.2 Theory and concepts

3.1 OBJECTIVE: Create tables and specify the queries in SQL

3.2 THEORY& CONCEPTS:


Introduction about SQL-
SQL (Structured Query Language) is a nonprocedural language, you specify what you want, not how
to get it. A block structured format of English key words is used in this query language. It has the
following components.

DDL (Data Definition Language)-


The SQL DDL provides command for defining relation schemas, deleting relations and modifying
relation schema.

DML (Data Manipulation Language)-


It includes commands to insert tuples into, delete tuples from and modify tuples in the database.

View definition-
The SQL DDL includes commands for defining views.
Transaction Control- SQL includes for specifying the beginning and ending of transactions.

Embedded SQL and Dynamic SQL-


Embedded and Dynamic SQL define how SQL statements can be embedded within general purpose
programming languages, such as C, C++, JAVA, COBOL, Pascal and Fortran.

Integrity-
The SQL DDL includes commands for specifying integrity constraints that the data stored in the
database must specify. Updates that violate integrity constraints are allowed.

Authorization-
The SQL DDL includes commands for specifying access rights to relations and views.

Data Definition Language-

The SQL DDL allows specification of not only a set of relations but also information about each
relation, including-
 Schema for each relation
 The domain of values associated with each attribute.
 The integrity constraints.
 The set of indices to be maintained for each relation.
 The security and authorization information for each relation.
 The physical storage structure of each relation on disk.

Domain types in SQL-

The SQL standard supports a variety of built in domain types, including-


 Char (n)- A fixed length character length string with user specified length .
 Varchar (n)- A variable character length string with user specified maximum length n.
 Int- An integer.
 Small integer- A small integer.
 Numeric (p, d)-A Fixed point number with user defined precision.
 Real, double precision- Floating point and double precision floating point numbers with
machine dependent precision.
 Float (n)- A floating point number, with precision of at least n digits.
 Date- A calendar date containing a (four digit) year, month and day of the month.
 Time- The time of day, in hours, minutes and seconds Eg.Time ’09:30:00’.
 Number- Number is used to store numbers (fixed or floating point).

DDL statement for creating a table-

Syntax-
Create table tablename (columnname datatype(size), columnname datatype(size));

Insertion of data into tables-

Syntax-
INSERT INTO tablename
[(columnname, columnname, ………)] Values(expression, expression);

Inserting data into a table from another table:

Syntax-
INSERT INTO tablename
SELECT columnname, columnname, …….
FROM tablename;

Insertion of selected data into a table from another table:

Syntax-
INSERT INTO tablename
SELECT columnname, columnname……..
FROM tablename
WHERE columnname= expression;
Retrieving of data from the tables-

Syntax-
SELECT * FROM tablename;

The retrieving of specific columns from a table-

Syntax-
SELECT columnname, columnname, ….
FROM tablename;

Elimination of duplicates from the select statement-

Syntax-
SELECT DISTINCT columnname, columnname
FROM tablename;

Selecting a data set from table data-

Syntax-
3(b) TITLE: DATA MANIPULATION LANGUAGE

3.1 Objective 3.2 Theory and concepts

3.1 OBJECTIVE: Perform manipulation operations on created tables.

3.2 THEORY AND CONCEPTS: DML (Data Manipulation Language) Data manipulation is

 The retrieval of information stored in the database.


 The insertion of new information into the database.
 The deletion of information from the database.
 The modification of information stored by the appropriate data model. There are basically two
types.
(i) Procedural DML:- require a user to specify what data are needed and how to get those
data.
(ii) Non Procedural DML: require a user to specify what data are needed without specifying
how to get those data.

Updating the content of a table:


In creation situation we may wish to change a value in table without changing all values in the tuple.
For this purpose the update statement can be used.

Update table name


Set columnname = expression, columnname =expression……
Where columnname = expression;

Deletion Operation:-
A delete request is expressed in much the same way as query. We can delete whole tuple (rows) we
can delete values on only particulars attributes.

Deletion of all rows

Syntax:
Delete from tablename;

Deletion of specified number of rows


Syntax:

Delete from table name


Where search condition;

Computation in expression lists used to select data

+ Addition - Subtraction
* Multiplication ** exponentiation
/ Division () Enclosed operation

Renaming columns used with Expression Lists: - The default output column names can be renamed
by the user if required

Syntax:
Select column name result_columnname,
Columnname result_columnname,
From table name;
Logical Operators:
The logical operators that can be used in SQL sentenced are

AND all of must be included


OR any of may be included
NOT none of could be included

Range Searching: Between operation is used for range searching.

Pattern Searching:
The most commonly used operation on string is pattern matching using the operation ‘like’ we
describe patterns by using two special characters.

 Percent (%) ; the % character matches any substring we consider the following examples.
 ‘Perry %’ matches any string beginning with perry
 ‘% idge % matches any string containing’ idge as substring.
 ‘ - - - ‘ matches any string exactly three characters.
 ‘ - - - % matches any string of at least of three characters.

Oracle functions:
Functions are used to manipulate data items and return result. Function follow the format of function
_name (argument1, argument2 ..) .An arrangement is user defined variable or constant. The structure
of function is such that it accepts zero or more arguments.

Examples:
i) Avg: return average value of n
Syntax: Avg ([distinct/all]n)
ii) Min: return minimum value of expr.
Syntax: MIN((distict/all )expr)
iii) Count: Returns the no of rows where expr is not null
Syntax: Count ([distinct/all)expr]
iv) Count (*): Returns the no rows in the table, including duplicates and those with nulls.
v) Max: Return max value of expr
Syntax:
Max ([distinct/all]expr)
vi) Sum: Returns sum of values of n
Syntax: Sum ([distinct/all]n)

Sorting of data in table


Syntax:
Select columnname, columnname
From table
Order by columnname;

You might also like