Professional Documents
Culture Documents
column level:
create table tablename(col datatype(size)
references mastertablename(primary key colname));
insertion:
Table created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SNO
----------
20
40
SNO
----------
10
20
40
SNO
----------
20
40
1 row deleted.
1 row deleted.
note:
whenever we are trying to delete master record
then oracle server returns an error,to overcome
this need to records from child table then only
we are able to delete master records
on deletecascade:
this clause is used along with foreign key
after using this we are easily deleting records
from master table
syntax:
create table tebalename(col datatype(size) references
mastertablename(primary key col) on delete cascade,..);
Table created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
SNO
----------
10
20
SNO
----------
20
10
1 row deleted.
SNO
----------
20
SNO
----------
20
on delete set null:
oracle also supports on delete set null along with
foreign key,after deletion records automatically
null will replaces
syntax:
Table created.
SQL> create table child(sno number(10) references mas on delete set null);
Table created.
1 row created.
1 row created.
1 row created.
SNO
----------
10
20
40
1 row created.
1 row created.
1 row created.
SNO
----------
10
20
40
1 row deleted.
SNO
----------
10
40
SNO
----------
10
40