You are on page 1of 15

SQL> create table Employee(EName varchar(10), SSN_No number(5) primary key, DoB

Date, City varchar(7), Sex varchar(6), Salary number(7,2), Manager_SSN number(5),


D_No number(3));
create table Employee(EName varchar(10), SSN_No number(5) primary key, DoB Date,
City varchar(7), Sex varchar(6), Salary number(7,2), Manager_SSN number(5), D_No
number(3))
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> drop table Employee;

Table dropped.

SQL> create table Employee(EName varchar(10), SSN_No number(5) primary key, DoB
Date, City varchar(7), Sex varchar(6), Salary number(7,2), Manager_SSN number(5),
D_No number(3));

Table created.

SQL> create table Department(DName varchar(10),D_Num number(5) primary key,MGR_SSN


number(5));
create table Department(DName varchar(10),D_Num number(5) primary key,MGR_SSN
number(5))
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> drop table Department;


drop table Department
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys

SQL> create table Department1(DName varchar(10),D_Num number(5) primary key,MGR_SSN


number(5));

Table created.

SQL> create table Works_On(SSN_Num number(5),Project_No number(5),Hours number(3));

Table created.

SQL> alter table Works_On add constraint pk primary key(SSN_Num,Project_No);


alter table Works_On add constraint pk primary key(SSN_Num,Project_No)
*
ERROR at line 1:
ORA-02264: name already used by an existing constraint

SQL> alter table Works_On add constraint pk1 primary key(SSN_Num,Project_No);


alter table Works_On add constraint pk1 primary key(SSN_Num,Project_No)
*
ERROR at line 1:
ORA-02264: name already used by an existing constraint
SQL> alter table Works_On add constraint pk_Works_On primary
key(SSN_Num,Project_No);

Table altered.

SQL> alter table Employee add constraint fk_Employee foreign key references
Employee;
alter table Employee add constraint fk_Employee foreign key references Employee
*
ERROR at line 1:
ORA-00906: missing left parenthesis

SQL> alter table Employee add constraint fk_Employee foreign key (Employee);
alter table Employee add constraint fk_Employee foreign key (Employee)
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> alter table Employee add constraint fk_Employee foreign key references
(Employee);
alter table Employee add constraint fk_Employee foreign key references (Employee)
*
ERROR at line 1:
ORA-00906: missing left parenthesis

SQL> alter table Employee add constraint fk_Employee foreign key (Manager_SSN)
references Employee;

Table altered.

SQL> alter table Employee add constraint foreign key (D_No) references Department;
alter table Employee add constraint foreign key (D_No) references Department
*
ERROR at line 1:
ORA-00902: invalid datatype

SQL> alter table Employee add constraint fK_Emp foreign key (D_No) references
Department;

Table altered.

SQL> alter table Works_On add constraint fK_Works foreign key (SSN_Num) references
Employee;

Table altered.

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Amit
Enter value for ssn_no: 1
Enter value for dob: 2-Jan-1995
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn:
Enter value for d_no: 1
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Amit',1,'2-Jan-
1995','Howrah','Male',50000,,1)
insert into Employee values('Amit',1,'2-Jan-1995','Howrah','Male',50000,,1)
*
ERROR at line 1:
ORA-00936: missing expression

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Amit
Enter value for ssn_no: 1
Enter value for dob: 2-Jan-1995
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn: null
Enter value for d_no: 1
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Amit',1,'2-Jan-
1995','Howrah','Male',50000,null,1)
insert into Employee values('Amit',1,'2-Jan-1995','Howrah','Male',50000,null,1)
*
ERROR at line 1:
ORA-02291: integrity constraint (RAHUL.FK_EMP) violated - parent key not found

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aman
Enter value for ssn_no: 101
Enter value for dob: 1-Jan-1993
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn:
Enter value for d_no: 1
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aman',101,'1-Jan-
1993','Howrah','Male',50000,,1)
insert into Employee values('Aman',101,'1-Jan-1993','Howrah','Male',50000,,1)
*
ERROR at line 1:
ORA-00936: missing expression

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aman
Enter value for ssn_no: 101
Enter value for dob: 1-Jan-1993
Enter value for city: Kolkata
Enter value for sex: Male
Enter value for salary: 40000
Enter value for manager_ssn: null
Enter value for d_no: 1
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aman',101,'1-Jan-
1993','Kolkata','Male',40000,null,1)
insert into Employee values('Aman',101,'1-Jan-1993','Kolkata','Male',40000,null,1)
*
ERROR at line 1:
ORA-02291: integrity constraint (RAHUL.FK_EMP) violated - parent key not found

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aman
Enter value for ssn_no: 101
Enter value for dob: 5-Sept-1997
Enter value for city: Kolkata
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn: 101
Enter value for d_no: 5
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aman',101,'5-Sept-
1997','Kolkata','Male',50000,101,5)
insert into Employee values('Aman',101,'5-Sept-1997','Kolkata','Male',50000,101,5)
*
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0

SQL> insert into Employee values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary);


Enter value for ename: Suman
Enter value for ssn_no: 1
Enter value for dob: 1-Jan-1992
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 50000
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary)
new 1: insert into Employee values('Suman',1,'1-Jan-1992','Howrah','Male',50000)
insert into Employee values('Suman',1,'1-Jan-1992','Howrah','Male',50000)
*
ERROR at line 1:
ORA-00947: not enough values

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aman
Enter value for ssn_no: 1
Enter value for dob: 1-Jan-1992
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 40000
Enter value for manager_ssn: 1
Enter value for d_no: ok
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aman',1,'1-Jan-
1992','Howrah','Male',40000,1,ok)
insert into Employee values('Aman',1,'1-Jan-1992','Howrah','Male',40000,1,ok)
*
ERROR at line 1:
ORA-00984: column not allowed here

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: 1
Enter value for ssn_no: df
Enter value for dob:
Enter value for city: wf
Enter value for sex:
Enter value for salary:
Enter value for manager_ssn:
Enter value for d_no:
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('1',df,'','wf','',,,)
insert into Employee values('1',df,'','wf','',,,)
*
ERROR at line 1:
ORA-00936: missing expression

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Amit
Enter value for ssn_no: 1
Enter value for dob: 1-Jan-1992
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 30000
Enter value for manager_ssn: null
Enter value for d_no: 5
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Amit',1,'1-Jan-
1992','Howrah','Male',30000,null,5)
insert into Employee values('Amit',1,'1-Jan-1992','Howrah','Male',30000,null,5)
*
ERROR at line 1:
ORA-02291: integrity constraint (RAHUL.FK_EMP) violated - parent key not found

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Amit
Enter value for ssn_no: 1
Enter value for dob: 1-Jan-1992
Enter value for city: Howrah
Enter value for sex: Male
Enter value for salary: 30000
Enter value for manager_ssn: null
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Amit',1,'1-Jan-
1992','Howrah','Male',30000,null,null)

1 row created.

Commit complete.
SQL> insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aman
Enter value for ssn_no: 2
Enter value for dob: 2-Feb-1994
Enter value for city: Hyderabadh
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn: 1
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aman',2,'2-Feb-
1994','Hyderabadh','Male',50000,1,null)
insert into Employee values('Aman',2,'2-Feb-1994','Hyderabadh','Male',50000,1,null)
*
ERROR at line 1:
ORA-12899: value too large for column "RAHUL"."EMPLOYEE"."CITY" (actual: 10,
maximum: 7)

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aman
Enter value for ssn_no: 2
Enter value for dob: 2-Feb-1993
Enter value for city: Kolkata
Enter value for sex: Male
Enter value for salary: 40000
Enter value for manager_ssn: 1
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aman',2,'2-Feb-
1993','Kolkata','Male',40000,1,null)

1 row created.

Commit complete.
SQL> select * from Employee;

ENAME SSN_NO DOB CITY SEX SALARY MANAGER_SSN D_NO


---------- ---------- --------- ------- ------ ---------- ----------- ----------
Amit 1 01-JAN-92 Howrah Male 30000
Aman 2 02-FEB-93 Kolkata Male 40000 1

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Tanya
Enter value for ssn_no: 3
Enter value for dob: 5-June-1996
Enter value for city: Bandel
Enter value for sex: Female
Enter value for salary: 50000
Enter value for manager_ssn: 1
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Tanya',3,'5-June-
1996','Bandel','Female',50000,1,null)

1 row created.

Commit complete.
SQL> insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Swanmoy
Enter value for ssn_no: 4
Enter value for dob: 6-Jul-1998
Enter value for city: Rishra
Enter value for sex: Male
Enter value for salary: 20000
Enter value for manager_ssn: 1
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Swanmoy',4,'6-Jul-
1998','Rishra','Male',20000,1,null)

1 row created.

Commit complete.
SQL> insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Arup
Enter value for ssn_no: 4
Enter value for dob: 11-Nov-1999
Enter value for city: Kolkata
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn: 1
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Arup',4,'11-Nov-
1999','Kolkata','Male',50000,1,null)
insert into Employee values('Arup',4,'11-Nov-1999','Kolkata','Male',50000,1,null)
*
ERROR at line 1:
ORA-00001: unique constraint (RAHUL.SYS_C007480) violated

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Arup
Enter value for ssn_no: 5
Enter value for dob: 11-Jun-1999
Enter value for city: Kolkata
Enter value for sex: Male
Enter value for salary: 50000
Enter value for manager_ssn: 1
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Arup',5,'11-Jun-
1999','Kolkata','Male',50000,1,null)

1 row created.

Commit complete.
SQL> insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Aritra
Enter value for ssn_no: 6
Enter value for dob: 12-Mar-1994
Enter value for city: Kolkata
Enter value for sex: Male
Enter value for salary: 40000
Enter value for manager_ssn: null
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Aritra',6,'12-Mar-
1994','Kolkata','Male',40000,null,null)

1 row created.

Commit complete.
SQL> insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Sumana
Enter value for ssn_no: 7
Enter value for dob: 11-Aug-1995
Enter value for city: Bandel
Enter value for sex: Female
Enter value for salary: 60000
Enter value for manager_ssn: 11-Aug-1995
Enter value for d_no:
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Sumana',7,'11-Aug-
1995','Bandel','Female',60000,11-Aug-1995,)
insert into Employee values('Sumana',7,'11-Aug-1995','Bandel','Female',60000,11-
Aug-1995,)

*
ERROR at line 1:
ORA-00936: missing expression

SQL> insert into Employee


values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Sumana
Enter value for ssn_no: 7
Enter value for dob: 11-Aug-1995
Enter value for city: Bandel
Enter value for sex: Female
Enter value for salary: 30000
Enter value for manager_ssn: 6
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Sumana',7,'11-Aug-
1995','Bandel','Female',30000,6,null)

1 row created.

Commit complete.
SQL> insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No);
Enter value for ename: Ishita
Enter value for ssn_no: 8
Enter value for dob: 09-Jun-1998
Enter value for city: Howrah
Enter value for sex: Female
Enter value for salary: 30000
Enter value for manager_ssn: 6
Enter value for d_no: null
old 1: insert into Employee
values('&Ename',&SSN_No,'&DoB','&City','&Sex',&Salary,&Manager_SSN,&D_No)
new 1: insert into Employee values('Ishita',8,'09-Jun-
1998','Howrah','Female',30000,6,null)

1 row created.

Commit complete.
SQL> select * from Employee;

ENAME SSN_NO DOB CITY SEX SALARY MANAGER_SSN D_NO


---------- ---------- --------- ------- ------ ---------- ----------- ----------
Amit 1 01-JAN-92 Howrah Male 30000
Aman 2 02-FEB-93 Kolkata Male 40000 1
Tanya 3 05-JUN-96 Bandel Female 50000 1
Swanmoy 4 06-JUL-98 Rishra Male 20000 1
Arup 5 11-JUN-99 Kolkata Male 50000 1
Aritra 6 12-MAR-94 Kolkata Male 40000
Sumana 7 11-AUG-95 Bandel Female 30000 6
Ishita 8 09-JUN-98 Howrah Female 30000 6

8 rows selected.

SQL> insert into Department values('&DName',&D_Num,&MGR_SSN);


Enter value for dname: Accounts
Enter value for d_num: 1
Enter value for mgr_ssn: 1
old 1: insert into Department values('&DName',&D_Num,&MGR_SSN)
new 1: insert into Department values('Accounts',1,1)
insert into Department values('Accounts',1,1)
*
ERROR at line 1:
ORA-00947: not enough values

SQL> insert into Department1 values('&DName',&D_Num,&MGR_SSN);


Enter value for dname: Accounts
Enter value for d_num: 1
Enter value for mgr_ssn: 1
old 1: insert into Department1 values('&DName',&D_Num,&MGR_SSN)
new 1: insert into Department1 values('Accounts',1,1)

1 row created.

Commit complete.
SQL> insert into Department1 values('&DName',&D_Num,&MGR_SSN);
Enter value for dname: Research
Enter value for d_num: 5
Enter value for mgr_ssn: 1
old 1: insert into Department1 values('&DName',&D_Num,&MGR_SSN)
new 1: insert into Department1 values('Research',5,1)

1 row created.

Commit complete.
SQL> insert into Department1 values('&DName',&D_Num,&MGR_SSN);
Enter value for dname: Sales
Enter value for d_num: 2
Enter value for mgr_ssn: 6
old 1: insert into Department1 values('&DName',&D_Num,&MGR_SSN)
new 1: insert into Department1 values('Sales',2,6)

1 row created.

Commit complete.
SQL> insert into Department1 values('&DName',&D_Num,&MGR_SSN);
Enter value for dname: HR
Enter value for d_num: 4
Enter value for mgr_ssn: 6
old 1: insert into Department1 values('&DName',&D_Num,&MGR_SSN)
new 1: insert into Department1 values('HR',4,6)

1 row created.

Commit complete.
SQL> select * from Department1;

DNAME D_NUM MGR_SSN


---------- ---------- ----------
Accounts 1 1
Research 5 1
Sales 2 6
HR 4 6

SQL> insert into Works_On values(&SSN_Num,&Project_No,&Hours);


Enter value for ssn_num: 1
Enter value for project_no: 1
Enter value for hours: 10
old 1: insert into Works_On values(&SSN_Num,&Project_No,&Hours)
new 1: insert into Works_On values(1,1,10)

1 row created.

Commit complete.
SQL> insert into Works_On values(&SSN_Num,&Project_No,&Hours);
Enter value for ssn_num: 2
Enter value for project_no: 1
Enter value for hours: 15
old 1: insert into Works_On values(&SSN_Num,&Project_No,&Hours)
new 1: insert into Works_On values(2,1,15)

1 row created.

Commit complete.
SQL> insert into Works_On values(&SSN_Num,&Project_No,&Hours);
Enter value for ssn_num: 2
Enter value for project_no: 2
Enter value for hours: 16
old 1: insert into Works_On values(&SSN_Num,&Project_No,&Hours)
new 1: insert into Works_On values(2,2,16)

1 row created.

Commit complete.
SQL> insert into Works_On values(&SSN_Num,&Project_No,&Hours);
Enter value for ssn_num: 3
Enter value for project_no: 1
Enter value for hours: 14
old 1: insert into Works_On values(&SSN_Num,&Project_No,&Hours)
new 1: insert into Works_On values(3,1,14)

1 row created.

Commit complete.
SQL> select * from Works_On;

SSN_NUM PROJECT_NO HOURS


---------- ---------- ----------
1 1 10
2 1 15
2 2 16
3 1 14

SQL> insert into Works_On values(&SSN_Num,&Project_No,&Hours);


Enter value for ssn_num: 5
Enter value for project_no: 3
Enter value for hours: 20
old 1: insert into Works_On values(&SSN_Num,&Project_No,&Hours)
new 1: insert into Works_On values(5,3,20)

1 row created.

Commit complete.
SQL> insert into Works_On values(&SSN_Num,&Project_No,&Hours);
Enter value for ssn_num: 4
Enter value for project_no: 3
Enter value for hours: 19
old 1: insert into Works_On values(&SSN_Num,&Project_No,&Hours)
new 1: insert into Works_On values(4,3,19)

1 row created.

Commit complete.
SQL> select * from Works_On;

SSN_NUM PROJECT_NO HOURS


---------- ---------- ----------
1 1 10
2 1 15
2 2 16
3 1 14
5 3 20
4 3 19

6 rows selected.

SQL> select * from Employee;

ENAME SSN_NO DOB CITY SEX SALARY MANAGER_SSN D_NO


---------- ---------- --------- ------- ------ ---------- ----------- ----------
Amit 1 01-JAN-92 Howrah Male 30000
Aman 2 02-FEB-93 Kolkata Male 40000 1
Tanya 3 05-JUN-96 Bandel Female 50000 1
Swanmoy 4 06-JUL-98 Rishra Male 20000 1
Arup 5 11-JUN-99 Kolkata Male 50000 1
Aritra 6 12-MAR-94 Kolkata Male 40000
Sumana 7 11-AUG-95 Bandel Female 30000 6
Ishita 8 09-JUN-98 Howrah Female 30000 6

8 rows selected.

SQL> select * from Department1;

DNAME D_NUM MGR_SSN


---------- ---------- ----------
Accounts 1 1
Research 5 1
Sales 2 6
HR 4 6

SQL> update table Employee set D_No=2 where Ename='Sumana';


update table Employee set D_No=2 where Ename='Sumana'
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> update Employee set D_No=2 where Ename='Sumana';


update Employee set D_No=2 where Ename='Sumana'
*
ERROR at line 1:
ORA-02291: integrity constraint (RAHUL.FK_EMP) violated - parent key not found

SQL> alter table Employee add constraint f_KEY foreign key (D_No) references
Department1;

Table altered.

SQL> alter table Employee drop constraint fK_Emp;

Table altered.

SQL> drop table Department;


drop table Department
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys

SQL> update Employee set D_No=2 where Ename='Sumana';

1 row updated.

Commit complete.
SQL> select * from Employee;

ENAME SSN_NO DOB CITY SEX SALARY MANAGER_SSN D_NO


---------- ---------- --------- ------- ------ ---------- ----------- ----------
Amit 1 01-JAN-92 Howrah Male 30000
Aman 2 02-FEB-93 Kolkata Male 40000 1
Tanya 3 05-JUN-96 Bandel Female 50000 1
Swanmoy 4 06-JUL-98 Rishra Male 20000 1
Arup 5 11-JUN-99 Kolkata Male 50000 1
Aritra 6 12-MAR-94 Kolkata Male 40000
Sumana 7 11-AUG-95 Bandel Female 30000 6 2
Ishita 8 09-JUN-98 Howrah Female 30000 6

8 rows selected.

SQL> select * from Department;

no rows selected

SQL> select * from Department1;

DNAME D_NUM MGR_SSN


---------- ---------- ----------
Accounts 1 1
Research 5 1
Sales 2 6
HR 4 6

SQL> select * from Works_On;

SSN_NUM PROJECT_NO HOURS


---------- ---------- ----------
1 1 10
2 1 15
2 2 16
3 1 14
5 3 20
4 3 19

6 rows selected.

SQL> update Employee set D_No=4 where Ename='Ishita';

1 row updated.

Commit complete.
SQL> update Employee set D_No=1 where Ename='Amit';

1 row updated.

Commit complete.
SQL> update Employee set D_No=5 where Ename='Aman';

1 row updated.

Commit complete.
SQL> update Employee set D_No=5 where Ename='Arup';

1 row updated.

Commit complete.
SQL> update Employee set D_No=5 where Ename='Tanya';

1 row updated.

Commit complete.
SQL> update Employee set D_No=1 where Ename='Swanmoy';

1 row updated.

Commit complete.
SQL> select * from Employee;

ENAME SSN_NO DOB CITY SEX SALARY MANAGER_SSN D_NO


---------- ---------- --------- ------- ------ ---------- ----------- ----------
Amit 1 01-JAN-92 Howrah Male 30000 1
Aman 2 02-FEB-93 Kolkata Male 40000 1 5
Tanya 3 05-JUN-96 Bandel Female 50000 1 5
Swanmoy 4 06-JUL-98 Rishra Male 20000 1 1
Arup 5 11-JUN-99 Kolkata Male 50000 1 5
Aritra 6 12-MAR-94 Kolkata Male 40000
Sumana 7 11-AUG-95 Bandel Female 30000 6 2
Ishita 8 09-JUN-98 Howrah Female 30000 6 4

8 rows selected.

SQL> update Employee set D_No=2 where Ename='Aritra';

1 row updated.

Commit complete.
SQL> select * from Employee;

ENAME SSN_NO DOB CITY SEX SALARY MANAGER_SSN D_NO


---------- ---------- --------- ------- ------ ---------- ----------- ----------
Amit 1 01-JAN-92 Howrah Male 30000 1
Aman 2 02-FEB-93 Kolkata Male 40000 1 5
Tanya 3 05-JUN-96 Bandel Female 50000 1 5
Swanmoy 4 06-JUL-98 Rishra Male 20000 1 1
Arup 5 11-JUN-99 Kolkata Male 50000 1 5
Aritra 6 12-MAR-94 Kolkata Male 40000 2
Sumana 7 11-AUG-95 Bandel Female 30000 6 2
Ishita 8 09-JUN-98 Howrah Female 30000 6 4

8 rows selected.

SQL> select ENmae from Employee where Manager_SSN=null;


select ENmae from Employee where Manager_SSN=null
*
ERROR at line 1:
ORA-00904: "ENMAE": invalid identifier

SQL> select ENmae from Employee where Manager_SSN is null;


select ENmae from Employee where Manager_SSN is null
*
ERROR at line 1:
ORA-00904: "ENMAE": invalid identifier

SQL> select EName from Employee where Manager_SSN is null;

ENAME
----------
Amit
Aritra

SQL> select EName,City from Employee e,Department d where d.D_Num=e.D_No and


d.DName='Research';
select EName,City from Employee e,Department d where d.D_Num=e.D_No and
d.DName='Research'
*
ERROR at line 1:
ORA-00904: "D"."D_NUM": invalid identifier

SQL> select EName,City from Employee e,Department1 d where d.D_Num=e.D_No and


d.DName='Research';

ENAME CITY
---------- -------
Aman Kolkata
Tanya Bandel
Arup Kolkata

SQL> select Project_No from Works_On w,Employee e where w.SSN_Num=e.SSN_No and


e.Manager_SSN is null;

PROJECT_NO
----------
1

SQL> select EName,City,Project_No from Works_On w,Employee e where


w.SSN_Num=e.SSN_No and e.Manager_SSN is null;

ENAME CITY PROJECT_NO


---------- ------- ----------
Amit Howrah 1

You might also like