8. Inserting Data into Tables: - once a table is created the most
natural thing to do is load this table with data to be manipulated later.
Syntax 1:
insert into <tablename> (<col1>,<col2>…..<col n>) values(<val 1>,
<val 2>…….<val n>);
Syntax 2:
insert into <tablename> values(&<col1>,&<col2>……,&<col n>);
Syntax 3:
insert into <tablename> values(<val 1>,<val 2>…….,<val n>);
Ex 1:
Insert into skc (sname,rollno,class,dob,fee_paid)
values(‘sri’,’104B’,’cse’,’27-feb-05’,10000.00);
Ex 2:
insert into skc values(&sname,&roll no,&class);
enter sname:’sri’
enter roll no:’104B’
enter class:’cse’
1 row created.
Ex 3:
insert into skc values(‘sri’,’104B’,cse’,’27-feb-05’,10000.00);
9. Delete operations.
a) remove all rows
Syntax:
delete from <tablename>;
b) removal of a specified row/s
Syntax:
delete from <tablename> where <condition>;
10. Updating the contents of a table.
a) updating all rows
Syntax:
Update <tablename> set <col>=<exp>,<col>=<exp>;
b) updating seleted records.
Syntax:
Update <tablename> set <col>=<exp>,<col>=<exp>
where <condition>;
11. Types of data constrains.
a) not null constraint at column level.
Syntax:
<col><datatype>(size)not null
b) unique constraint
Syntax:
Unique constraint at column level.
<col><datatype>(size)unique;
c) unique constraint at table level:
Syntax:
Create table
tablename(col=format,col=format,unique(<col1>,<col2>);
d) primary key constraint at column level
Syntax:
<col><datatype>(size)primary key;
e) primary key constraint at table level.
Syntax:
Create table tablename(col=format,col=format
primary key(col1>,<col2>);
f) foreign key constraint at column level.
Syntax:
<col><datatype>(size>) references <tablename>[<col>];
g) foreign key constraint at table level
Syntax:
foreign key(<col>[,<col>]) references
<tablename>[(<col>,<col>)
h) check constraint
check constraint constraint at column level.
Syntax: <col><datatype>(size) check(<logical expression>)
i) check constraint constraint at table level.
Syntax: check(<logical expression>)