Anda di halaman 1dari 4

SQL> create table employees(eid integer primary key,ename char(20),designation c

har(20));
Table created.
SQL> insert into employees values(1,'vijay','employee');
1 row created.
SQL> insert into employees values(2,'radha','prof');
1 row created.
SQL> insert into employees values(3,'sharan','student');
1 row created.
SQL> insert into employees values(4,'priya','prof');
1 row created.
SQL> insert into employees values(5,'vishnu','manager');
1 row created.
SQL> select * from employees;
EID
---------1
2
3
4
5

ENAME
-------------------vijay
radha
sharan
priya
vishnu

DESIGNATION
-------------------employee
prof
student
prof
manager

SQL> create table department(did integer primary key,dname char(20),budget integ


er);
Table created.
SQL> insert into department values(1,'cse',2000);
1 row created.
SQL> insert into department values(2,'ece',4000);
1 row created.
SQL> insert into department values(3,'mech',3500);
1 row created.
SQL> insert into department values(4,'mech',6600);
1 row created.
SQL> insert into department values(5,'civil',8800);
1 row created.

SQL> select * from department;


DID
---------1
2
3
4
5

DNAME
BUDGET
-------------------- ---------cse
2000
ece
4000
mech
3500
mech
6600
civil
8800

SQL> create table project(pid integer primary key,pname char(20),duration intege


r);
Table created.
SQL> insert into project values(1,'comp',2);
1 row created.
SQL> insert into project values(2,'it',3);
1 row created.
SQL> insert into project values(3,'ece',5);
1 row created.
SQL> insert into project values(4,'comp',8);
1 row created.
SQL> insert into project values(5,'cse',6);
1 row created.
SQL> select * from project;
PID
---------1
2
3
4
5

PNAME
DURATION
-------------------- ---------comp
2
it
3
ece
5
comp
8
cse
6

SQL> create table monitors(eid integer,pid integer,did integer,until date,constr


aint pk1 primary key(eid,did,pid),constraint fk1 foreign key(eid) references emp
loyees,constraint fk2 foreign key(pid) references project,constraint fk3 foreign
key(did) references department);
Table created.
SQL> insert into monitors values(1,1,1,'08 may 95');
1 row created.
SQL> insert into monitors values(2,2,2,'18 april 74');
1 row created.

SQL> insert into monitors values(2,1,2,'30 aug 96');


1 row created.
SQL> insert into monitors values(3,3,3,'30 aug 96');
1 row created.
SQL> insert into monitors values(5,4,4,'29 july 79');
1 row created.
SQL> select * from monitors;
EID
PID
DID UNTIL
---------- ---------- ---------- --------1
1
1 08-MAY-95
2
2
2 18-APR-74
2
1
2 30-AUG-96
3
3
3 30-AUG-96
5
4
4 29-JUL-79
SQL> delete from monitors where eid=1;
1 row deleted.
SQL> delete from monitors where pid=1;
1 row deleted.
SQL> select * from monitors;
EID
PID
DID UNTIL
---------- ---------- ---------- --------2
2
2 18-APR-74
3
3
3 30-AUG-96
5
4
4 29-JUL-79
SQL> delete from department where did=3;
delete from department where did=3
*
ERROR at line 1:
ORA-02292: integrity constraint (SYSTEM.FK3) violated - child record found
SQL> update employees e set e.eid=1 where e.eid=5;
update employees e set e.eid=1 where e.eid=5
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C0010169) violated
SQL> update monitors m set m.eid=1 where m.eid=5;
1 row updated.
SQL> select * from monitors;
EID

PID

DID UNTIL

---------- ---------- ---------- --------2


2
2 18-APR-74
3
3
3 30-AUG-96
1
4
4 29-JUL-79
SQL> update monitors m set m.did=1 where m.did=4;
1 row updated.
SQL> select * from monitors;
EID
PID
DID UNTIL
---------- ---------- ---------- --------2
2
2 18-APR-74
3
3
3 30-AUG-96
1
4
1 29-JUL-79
SQL> spool off;