create table emp(eid int primary key,ename varchar2(20) not null,age int,designation char(20) not null,sal int)
Table created.
insert into emp(eid,ename,age,designation,sal)values(101,'a',25,'programmer',20000)
1 row(s) inserted.
insert into emp(eid,ename,age,designation,sal)values(102,'b',26,'developer',20000)
1 row(s) inserted.
insert into emp(eid,ename,age,designation,sal)values(103,'c',27,'analyst',20000)
1 row(s) inserted.
select *from emp
EID | ENAME | AGE | DESIGNATION | SAL | 101 | a | 25 | programmer | 20000 | 103 | c | 27 | analyst | 20000 | 102 | b | 26 | developer | 20000 |
---|
create table dep_policy(eid int,name char(10),age int,primary key(eid,name),foreign key(eid) references emp(eid))
Table created.
insert into dep_policy values(101,'abc',20)
1 row(s) inserted.
insert into dep_policy values(102,'xyz',20)
1 row(s) inserted.
insert into dep_policy values(101,'xyz',20)
1 row(s) inserted.
select *from dep_policy
EID | NAME | AGE | 101 | abc | 20 | 102 | xyz | 20 | 101 | xyz | 20 |
---|
delete from emp where eid=101
ORA-02292: integrity constraint (SQL_HPHNATQIXIBTMGZEBRAWVVPHV.SYS_C0063638054) violated - child record found ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-02292
drop table dep_policy
Table dropped.
create table dep_policy(eid int,name char(10),age int,primary key(eid,name),foreign key(eid) references emp(eid) on delete cascade )
Table created.
insert into dep_policy values(101,'abc',20)
1 row(s) inserted.
insert into dep_policy values(102,'xyz',20)
1 row(s) inserted.
insert into dep_policy values(101,'xyz',20)
1 row(s) inserted.
select *from dep_policy
EID | NAME | AGE | 101 | abc | 20 | 102 | xyz | 20 | 101 | xyz | 20 |
---|
delete from emp where eid=101
1 row(s) deleted.
select *from dep_policy
EID | NAME | AGE | 102 | xyz | 20 |
---|
select *from emp
EID | ENAME | AGE | DESIGNATION | SAL | 103 | c | 27 | analyst | 20000 | 102 | b | 26 | developer | 20000 |
---|
drop table emp
ORA-02449: unique/primary keys in table referenced by foreign keysMore Details: https://docs.oracle.com/error-help/db/ora-02449
drop table dep_policy
Table dropped.
drop table emp
Table dropped.
create table emp(eid int primary key,ename varchar2(20) not null,age int,designation char(20) not null,sal int)
Table created.
insert into emp(eid,ename,age,designation,sal)values(101,'a',25,'programmer',20000)
1 row(s) inserted.
insert into emp(eid,ename,age,designation,sal)values(102,'b',26,'developer',20000)
1 row(s) inserted.
insert into emp(eid,ename,age,designation,sal)values(103,'c',27,'analyst',20000)
1 row(s) inserted.
create table dep_policy(eid int,name char(10),age int,primary key(eid,name),foreign key(eid) references emp(eid) on delete set null)
Table created.
insert into dep_policy values(101,'abc',20)
1 row(s) inserted.
insert into dep_policy values(102,'xyz',20)
1 row(s) inserted.
insert into dep_policy values(103,'xyz',20)
1 row(s) inserted.
select *from dep_policy
EID | NAME | AGE | 101 | abc | 20 | 102 | xyz | 20 | 103 | xyz | 20 |
---|
delete from emp where eid=101
ORA-01407: cannot update ("SQL_HPHNATQIXIBTMGZEBRAWVVPHV"."DEP_POLICY"."EID") to NULL ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-01407
drop table dep_policy
Table dropped.
drop table emp
Table dropped.
create table emp(eid int primary key,ename varchar2(20) not null,age int,designation char(20) not null,sal int)
Table created.
insert into emp(eid,ename,age,designation,sal)values(101,'a',25,'programmer',20000)
1 row(s) inserted.
insert into emp(eid,ename,age,designation,sal)values(102,'b',26,'developer',20000)
1 row(s) inserted.
insert into emp(eid,ename,age,designation,sal)values(103,'c',27,'analyst',20000)
1 row(s) inserted.
select *from emp
EID | ENAME | AGE | DESIGNATION | SAL | 101 | a | 25 | programmer | 20000 | 102 | b | 26 | developer | 20000 | 103 | c | 27 | analyst | 20000 |
---|
create table contract(eid int default 101,cid int primary key,foreign key(eid) references emp on delete set null)
Table created.
insert into contract values(101,201)
1 row(s) inserted.
insert into contract values(101,202)
1 row(s) inserted.
select *from contract
EID | CID | 101 | 201 | 101 | 202 |
---|
delete from emp where eid=101
1 row(s) deleted.
select *from contract
EID | CID | - | 201 | - | 202 |
---|