Structured Query Language (SQL) Is A Language
Structured Query Language (SQL) Is A Language
• Insert
• Update
• Delete
• Select
Data Control Language
DCL includes the commands that related to the
security of the database. The commands of
DCL are:
• Grant
• Revoke
Create Table Command
Create table command is used to define a new
table.
Syntax:
Create table table-name(column1 datatype (size),
column2 datatype (size),
------,
columnN datatype (size));
Constraints in Create Table
Command
Syntax:
Syntax:
Syntax:
Column-name datatype (size) Not Null
Foreign Key Constraint
Foreign key is a column whose values are derived from the
primary key of other table. Foreign key has following
characteristics:
• Foreign key can contain only those values that are present in
the primary key of the master table.
• The values in the foreign key can be null or duplicate values.
• In foreign key, if we insert a value that is not present in the
primary key of master table then, that record will be rejected
by Oracle engine.
• A record in the master table can not be deleted if the
corresponding record in the foreign table exists.
Foreign Key Constraint
Syntax:
Syntax:
Column-name Datatype (size) Check (Boolean
Expression)
Alter Table Command
Syntax:
• Syntax:
• Syntax:
• Syntax:
– To add primary key:
Alter table table-name ADD
Primary Key (column-name);
– To add other constraints:
Alter table table-name ADD
(Constraint-definition);
Dropping the Constraints
• Syntax:
• Syntax:
Alter table table-name DROP
column column-name;
Drop Table Command
Syntax:
Drop table table-name;
Rename Command
Update table-name
SET
Column-Name1 = Value1,...,
Column- NameN = ValueN;
Update Command
The syntax for updating a selected set of rows is as
follows:
• Syntax:
Update table-name
SET
Column-Namel = Value1,....,
Column-NameN = ValueN
Where Condition;
Delete Command
Syntax:
Select-Statement1
UNION/INTERSECT/MINUS
Select-Statement2;
Select command with DUAL
Table
Sysdate
-------------
20-Jan-09
Select command with Aggregate
Functions
Aggregate functions are the Oracle functions that take a
collection of values as an input and produce a single
value as an output. Aggregate functions can be
applied on any column of numeric type. There are
five aggregate functions and they are:
• Avg
• Min
• Max
• Sum
• Count
Select command with Group By
clause
Group by clause creates a data set that contains several
sets of records grouped together based on a condition.
The syntax for group by clause is as follows:
Syntax:
Select C1, C2,..., Cn
Aggregate-Function(Column-Name)
From Table-Name
Where condition
Group By C1, C2,..., Cn;
Select command with Having
clause