You are on page 1of 39

SHUBHAM KUMAR

20BCE0101

DBMS LAB ASSIGNMENT

===========================================================================

EXERCISE 1

CREATE TABLE EMPLOYEE (FIRST_NAME


VARCHAR(15),
MID_NAME CHAR(2),
LAST_NAME VARCHAR(15),
SSN_NUMBER CHAR(9),
BIRTHDAY DATE,
ADDRESS VARCHAR2(50),
SEX CHAR(1),
SALARY NUMBER(7),
SUPERVISOR_SSN CHAR(9),
DEPARTMENT_NUMBER NUMBER(5));

CREATE TABLE DEPARTMENT (


DEPT_NAME VARCHAR2(15),
DEPT_NO NUMBER(5),
MANAGERSSN CHAR(9),
MANAGESTARTDATE DATE);

CREATE TABLE PROJECT(


PROJECTNAME VARCHAR2(15),
PROJECTNUMBER NUMBER(5),
PROJECTLOCATION VARCHAR2(15),
DEPT_NO NUMBER(5));

SQL> //1. Insert the data given above in employee, department and project tables.

1 row created.

SQL> //FOR TABLE EMPLOYEE


1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Doug', 'E', 'Gilbert', 554433221, '09-JUN-60', '11 S 59 E,
Salt Lake City, UT', 'M', 80000, NULL , 3);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Joyce', NULL, 'PAN', 543216789, '07-FEB-78', '35 S 18 E,
Salt Lake City, UT', 'F', 70000, NULL, 2);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Frankin', 'T', 'Wong', 333445555, '08-DEC-45', '638 Voss,
Houston, TX', 'M', 40000, 554433221, 5);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Jennifer', 'S', 'Wallace', 987654321, '20-JUN-31', '291
Berry, Bellaire, TX', 'F', 43000, 554433221, 4);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Johny', 'B', 'Smith', 123456789, '09-JAN-55', '731 Fondren,
Houston, TX', 'M', 30000, 333445555, 5);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Ramesh', 'K', 'Narayan', 666884444, '15-SEP-52', '975 Fire
Oak, Humble, TX', 'M', 38000, 333445555, 5);
1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Joyce', 'A', 'English', 453453453, '31-JUL-62', '5631 Rice,
Houston, TX', 'F', 25000, 333445555, 5);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('James', 'E', 'Borg', 888665555, '10-NOV-27', '450 Stone,
Houston, TX', 'M', 55000, 543216789, 1);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Alicia', 'J', 'Zelaya', 999887777, '19-JUL-58', '3321 Castle,
Spring, TX', 'F', 25000, 987654321, 4);

1 row created.

SQL> INSERT INTO EMPLOYEE VALUES('Ahmad', 'V', 'Jabbar', 987987987, '29-MAR-59', '980 Dallas,
Houston, TX', 'M', 25000, 987654321, 4);

1 row created

SQL> //FOR TABLE DEPARTMENT

1 row created.

SQL> INSERT INTO DEPARTMENT VALUES('Manufacture', 1, 888665555, '19-JUN-71');


1 row created.

SQL> INSERT INTO DEPARTMENT VALUES('Administration', 2, 543216789, '04-JAN-99');

1 row created.

SQL> INSERT INTO DEPARTMENT VALUES('Headquarter', 3, 554433221, '22-SEP-55');

1 row created.

SQL> INSERT INTO DEPARTMENT VALUES('Finance', 4, 987654321, '01-JAN-85');

1 row created.

SQL> INSERT INTO DEPARTMENT VALUES('Research', 5, 333445555, '22-MAY-78');

1 row created.

SQL>

SQL>

SQL> //FOR TABLE PROJECT

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectA', 3388, 'Houston', 1 );

1 row created.
SQL> INSERT INTO PROJECT VALUES('ProjectB', 1945, 'Salt Lake City', 3 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectC', 6688, 'Houston', 5 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectD', 2423, 'Bellaire', 4 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectE', 7745, 'Sugarland', 5 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectF', 1566, 'Salt Lake City', 3 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectG', 1234, 'New York', 2 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectH', 3467, 'Stafford', 4 );


1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectI', 4345, 'Chicago', 1 );

1 row created.

SQL> INSERT INTO PROJECT VALUES('ProjectJ', 2212, 'San Francisco', 2 );

1 row created.

SQL> // 2. Display all the employees’ information.

1 row created.

SQL> SELECT * FROM EMPLOYEE WHERE DEPARTMENT_NUMBER=1;

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

James E Borg 888665555 10-NOV-27

450 Stone, Houston, TX M 55000 543216789

James E Borg 888665555 10-NOV-27

450 Stone, Houston, TX M 55000 543216789

1
FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

SQL> SELECT * FROM EMPLOYEE WHERE DEPARTMENT_NUMBER=2;

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Joyce PAN 543216789 07-FEB-78

35 S 18 E, Salt Lake City, UT F 70000

Joyce PAN 543216789 07-FEB-78

35 S 18 E, Salt Lake City, UT F 70000

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO


-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

SQL> SELECT * FROM EMPLOYEE WHERE DEPARTMENT_NUMBER=3;

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Doug E Gilbert 554433221 09-JUN-60

11 S 59 E, Salt Lake City, UT M 80000

Doug E Gilbert 554433221 09-JUN-60

11 S 59 E, Salt Lake City, UT M 80000

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------
SQL> SELECT * FROM EMPLOYEE WHERE DEPARTMENT_NUMBER=4;

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Jennifer S Wallace 987654321 20-JUN-31

291 Berry, Bellaire, TX F 43000 554433221

Alicia J Zelaya 999887777 19-JUL-58

3321 Castle, Spring, TX F 25000 987654321

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Ahmad V Jabbar 987987987 29-MAR-59

980 Dallas, Houston, TX M 25000 987654321


4

Ahmad V Jabbar 987987987 29-MAR-59

980 Dallas, Houston, TX M 25000 987654321

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Jennifer S Wallace 987654321 20-JUN-31

291 Berry, Bellaire, TX F 43000 554433221

Alicia J Zelaya 999887777 19-JUL-58

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

3321 Castle, Spring, TX F 25000 987654321

4
Ahmad V Jabbar 987987987 29-MAR-59

980 Dallas, Houston, TX M 25000 987654321

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Ahmad V Jabbar 987987987 29-MAR-59

980 Dallas, Houston, TX M 25000 987654321

8 rows selected.

SQL> SELECT * FROM EMPLOYEE WHERE DEPARTMENT_NUMBER=5;

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------
Frankin T Wong 333445555 08-DEC-45

638 Voss, Houston, TX M 40000 554433221

Johny B Smith 123456789 09-JAN-55

731 Fondren, Houston, TX M 30000 333445555

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

Ramesh K Narayan 666884444 15-SEP-52

975 Fire Oak, Humble, TX M 38000 333445555

Joyce A English 453453453 31-JUL-62

5631 Rice, Houston, TX F 25000 333445555

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER
-----------------

Frankin T Wong 333445555 08-DEC-45

638 Voss, Houston, TX M 40000 554433221

Johny B Smith 123456789 09-JAN-55

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------

DEPARTMENT_NUMBER

-----------------

731 Fondren, Houston, TX M 30000 333445555

Ramesh K Narayan 666884444 15-SEP-52

975 Fire Oak, Humble, TX M 38000 333445555

FIRST_NAME MI LAST_NAME SSN_NUMBE BIRTHDAY

--------------- -- --------------- --------- ---------

ADDRESS S SALARY SUPERVISO

-------------------------------------------------- - ---------- ---------


DEPARTMENT_NUMBER

-----------------

Joyce A English 453453453 31-JUL-62

5631 Rice, Houston, TX F 25000 333445555

SQL> //3. Display Employee name along with his SSN and Supervisor SSN.

1 ROW CREATED

SQL> SELECT FIRST_NAME, MID_NAME, LAST_NAME, SSN_NUMBER, SUPERVISOR_SSN FROM


EMPLOYEE;

FIRST_NAME MI LAST_NAME SSN_NUMBE SUPERVISO

--------------- -- --------------- --------- ---------

Doug E Gilbert 554433221

Joyce PAN 543216789

Frankin T Wong 333445555 554433221

Jennifer S Wallace 987654321 554433221

Johny B Smith 123456789 333445555

Ramesh K Narayan 666884444 333445555

Joyce A English 453453453 333445555

James E Borg 888665555 543216789

Alicia J Zelaya 999887777 987654321

Ahmad V Jabbar 987987987 987654321

Ahmad V Jabbar 987987987 987654321

FIRST_NAME MI LAST_NAME SSN_NUMBE SUPERVISO

--------------- -- --------------- --------- ---------

Doug E Gilbert 554433221


Joyce PAN 543216789

Frankin T Wong 333445555 554433221

Jennifer S Wallace 987654321 554433221

Johny B Smith 123456789 333445555

Ramesh K Narayan 666884444 333445555

Joyce A English 453453453 333445555

James E Borg 888665555 543216789

Alicia J Zelaya 999887777 987654321

Ahmad V Jabbar 987987987 987654321

Ahmad V Jabbar 987987987 987654321

SQL> // 4. Display the employee names whose bdate is ’29-MAR-1959’.

1 ROW CREATED

SQL> SELECT FIRST_NAME, LAST_NAME, BIRTHDAY FROM EMPLOYEE WHERE BIRTHDAY='29-MAR-


1959';

FIRST_NAME LAST_NAME BIRTHDAY

--------------- --------------- ---------

Ahmad Jabbar 29-MAR-59

Ahmad Jabbar 29-MAR-59

Ahmad Jabbar 29-MAR-59

Ahmad Jabbar 29-MAR-59

SQL> //5. Display salary of the employees without duplications.

SQL> SELECT DISTINCT SALARY, FIRST_NAME,LAST_NAME FROM EMPLOYEE;

SALARY FIRST_NAME LAST_NAME

---------- --------------- ---------------

25000 Joyce English

43000 Jennifer Wallace


80000 Doug Gilbert

38000 Ramesh Narayan

70000 Joyce PAN

30000 Johny Smith

40000 Frankin Wong

55000 James Borg

25000 Alicia Zelaya

25000 Ahmad Jabbar

SQL> // 6. Display the MgrSSN, MgrStartDate of the manager of ‘Finance’ department.

SQL> SELECT MANAGERSSN, MANAGERSTARTDATE FROM DEPARTMENT WHERE


DEPARTMENT_NAME='Research';

MANAGERSS MANAGERST

--------- ---------

333445555 22-MAY-78

333445555 22-MAY-78

SQL> // 7. Modify the department number of an employee having fname as ‘Joyce’ to 5

SQL> UPDATE EMPLOYEE SET DEPARTMENT_NUMBER=5 WHERE FIRST_NAME= 'JOYCE';

0 rows updated.

SQL> // 8. Alter Table department add column DepartmentPhoneNum of NUMBER data type and
insert values into this column only.

SQL> ALTER TABLE DEPARTMENT ADD CONTACT_NUMBER NUMBER(10);

Table altered

SQL> UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


DEPARTMENT_NUMBER=1;

2 rows updated.
SQL> UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE
DEPARTMENT_NUMBER=2;

2 rows updated.

SQL> UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


DEPARTMENT_NUMBER=3;

2 rows updated.

SQL> UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


DEPARTMENT_NUMBER=4;

2 rows updated.

SQL> UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


DEPARTMENT_NUMBER=5;

4 rows updated.

SQL> // 9. Alter table orders modify the size of DepartmentPhoneNum.

SQL> ALTER TABLE DEPARTMENT MODIFY CONTACT_NUMBER NUMBER(11);

Table altered

SQL> // 10. Modify the field name DepartmentPhoneNum of departments table to PhNo.

SQL> ALTER TABLE DEPARTMENT RENAME COLUMN CONTACT_NUMBER TO PHNO;

Table altered.

SQL> //11. Rename Table Department as DEPT.

SQL> RENAME DEPARTMENT TO DEPT;


Table renamed.

SQL> //12. Alter Table department remove column DepartmentPhoneNum.

ALTER TABLE DEPARTMENT DROP COLUMN CONTACT_NO;

Table altered

Column dropped.

SQL> //13. Create a table COPYOFDEPT as a copy of the table DEPT.

SQL> CREATE TABLE COPYOF_DEPT AS SELECT * FROM DEPT;

Table created.

SQL> //14. Delete all the rows from COPYOF DEPT table.

SQL> DELETE FROM COPYOF_DEPT WHERE DEPARTMENT_NUMBER=1;

2 rows deleted.

SQL> DELETE FROM COPYOF_DEPT WHERE DEPARTMENT_NUMBER=2;

2 rows deleted.

SQL> DELETE FROM COPYOF_DEPT WHERE DEPARTMENT_NUMBER=3;

2 rows deleted.

SQL> DELETE FROM COPYOF_DEPT WHERE DEPARTMENT_NUMBER=4;

2 rows deleted.
SQL> DELETE FROM COPYOF_DEPT WHERE DEPARTMENT_NUMBER=5;

4 rows deleted.

SQL>//15. Remove COPYOF DEPT table.

SQL> DROP TABLE COPYOF_DEPT;

Table dropped.

!!!!!===========================================================================!!!

Exercise 2
==============================================================================

create table employee

( firstname varchar(15) NOT NULL, midname char(2),

lastname varchar(15) NOT NULL, ssn char(9) NOT NULL PRIMARY KEY,

birthday date, address varchar(50), sex char(1) CHECK (sex in ('M','F','m','f')),

salary number(7), supervisorssn char(9),departmentnumber number(5)

CONSTRAINT chk_suprssn FOREIGN KEY (supervisorssn)

REFERENCES employee(ssn) ON DELETE NOT NULL)

create table employee

( firstname varchar(15) NOT NULL, midname char(2),

lastname varchar(15) NOT NULL, ssn char(9) NOT NULL PRIMARY KEY,

birthday date, address varchar(50), sex char(1) CHECK (sex in ('M','F','m','f')),

salary number(7), supervisorssn char(9),departmentnumber number(5),

CONSTRAINT chk_suprssn FOREIGN KEY (supervisorssn)

REFERENCES employee(ssn) ON DELETE NOT NULL)

;
create table employee

( firstname varchar(15) NOT NULL, midname char(2),

lastname varchar(15) NOT NULL, ssn char(9) NOT NULL PRIMARY KEY,

birthday date, address varchar(50), sex char(1) CHECK (sex in ('M','F','m','f')),

salary number(7), supervisorssn char(9),departmentnumber number(5),

CONSTRAINT chk_suprssn FOREIGN KEY (supervisorssn)

REFERENCES employee(ssn) ON DELETE SET NULL)

create table department

( departmentname varchar(15) NOT NULL,

departmentnumber number(5) NOT NULL PRIMARY KEY, managerssn char(9),

managestartdate date,CONSTRAINT chk_ssn FOREIGN KEY (managerssn)

REFERENCES employee(ssn) ON DELETE SET NULL)

alter table employee

add CONSTRAINT chk_deptNo

FOREIGN KEY (departmentnumber) REFERENCES department(departmentnumber)

ON DELETE CASCADE

create table dept_locations

( departmentnumber number(5), departmentlocation varchar(15),

CONSTRAINT chk_deptno2 FOREIGN KEY (departmentnumber)

REFERENCES department(departmentnumber) ON DELETE CASCADE )


;

create table projects

( projectname varchar(15) NOT NULL, projectnumber number(5) NOT NULL PRIMARY KEY,

projectlocation varchar(15), departmentnumber number(5)

CONSTRAINT chk_deptno3 FOREIGN KEY (departmentnumber)

REFERENCES department(departmentnumber) ON DELETE CASCADE )

create table projects

( projectname varchar(15) NOT NULL, projectnumber number(5) NOT NULL PRIMARY KEY,

projectlocation varchar(15), departmentnumber number(5),

CONSTRAINT chk_deptno3 FOREIGN KEY (departmentnumber)

REFERENCES department(departmentnumber) ON DELETE CASCADE )

create table works_on

( employeessn char(9), projectnumber int(5),

hours decimal(3,1) NOT NULL,

CONSTRAINT chl_ssn2 FOREIGN KEY (employeessn) REFERENCES employee(ssn)

CONSTRAINT chl_projectno FOREIGN KEY (projectnumber)

REFERENCES projects(projectnumber))

create table works_on

( employeessn char(9), projectnumber int(5),

hours decimal(3,1) NOT NULL,


CONSTRAINT chl_ssn2 FOREIGN KEY (employeessn) REFERENCES employee(ssn),

CONSTRAINT chl_projectno FOREIGN KEY (projectnumber)

REFERENCES projects(projectnumber))

create table works_on

( employeessn char(9), projectnumber int(5),

hours decimal(3,1) NOT NULL,

CONSTRAINT chl_ssn2 FOREIGN KEY (employeessn) REFERENCES employee(ssn)

ON DELETE CASCADE)

create table works_on

( employeessn char(9), projectnumber int(5),

hours decimal(3,1) NOT NULL,

CONSTRAINT chl_ssn2 FOREIGN KEY (employeessn) REFERENCES employee(ssn)

ON DELETE CASCADE)

create table works_on

( employeessn char(9), projectnumber int(5),

hours decimal(3,1) NOT NULL,

CONSTRAINT chk_ssn FOREIGN KEY (employeessn) REFERENCES employee(ssn)

ON DELETE SET NULL)

create table works_on


( employeessn char(9), projectnumber number(5),

hours decimal(3,1) NOT NULL,

CONSTRAINT chk_ssn2 FOREIGN KEY (employeessn)

REFERENCES employee(ssn) ON DELETE CASCADE,

CONSTRAINT chk_pjtno FOREIGN KEY (projectnumber)

REFERENCES projects(projectnumber) ON DELETE CASCADE )

create table dependents

( employeessn char(9), departmentname varchar(15),

sex char(1) CHECK (sex in ('M','F','m','f')),

birthday date, relationship varchar(8),

CONSTRAINT chk_ssn3 FOREIGN KEY (employeessn)

REFERENCES employee(ssn) ON DELETE CASCADE )

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Franklin','T','Wong',333445555,'08-DEC-45','638 Voss,Houston, TX','M',40000,554433221,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Jennifer','S','Wallace',987654321,'20-JUN-31','291 Berry,Bellaire, TX','F',43000,554433221,4)

insert into employee


(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('John','B','Smith',123456789,'09-JAN-55','731 Fondren,Houston, TX','M',30000,333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Ramesh','K','Narayan',666884444,'15-SEP-52','975 Fire Oak,Humble, TX','M',38000,333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Joyce','A','English',453453453,'31-JUL-62','5631 Rice,Houston, TX','F',25000, 333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('James','E','Borg',888665555,'10-NOV-27','450 Stone,Houston, TX','M',55000, 543216789,1)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Alica','J','Zelaya',999887777,'19-JUL-58','3321 Castle,Spring, TX','F',25000, 987654321,4)

;
insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Ahmad','V','Jabbar',987987987,'29-MAR59','980 Dallas,Houston, TX','M',25000, 987654321,4)

insert into department

( departmentname, departmentnumber, managestartdate) values ('Manufacture', 1,'19-JUN-71')

insert into department

( departmentname, departmentnumber, managestartdate) values ('Administration', 2,'04-JAN-99')

insert into department

( departmentname, departmentnumber, managestartdate) values ('Headquater', 3,'22-SEP-55')

insert into department

( departmentname, departmentnumber, managestartdate) values ('Finance', 4,'01-JAN-85')

insert into department

( departmentname, departmentnumber, managestartdate) values ('Research', 5,'22-MAY-78')

insert into employee


(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Franklin','T','Wong',333445555,'08-DEC-45','638 Voss,Houston, TX','M',40000,554433221,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Jennifer','S','Wallace',987654321,'20-JUN-31','291 Berry,Bellaire, TX','F',43000,554433221,4)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('John','B','Smith',123456789,'09-JAN-55','731 Fondren,Houston, TX','M',30000,333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Ramesh','K','Narayan',666884444,'15-SEP-52','975 Fire Oak,Humble, TX','M',38000,333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Joyce','A','English',453453453,'31-JUL-62','5631 Rice,Houston, TX','F',25000, 333445555,5)

;
insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('James','E','Borg',888665555,'10-NOV-27','450 Stone,Houston, TX','M',55000, 543216789,1)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Alica','J','Zelaya',999887777,'19-JUL-58','3321 Castle,Spring, TX','F',25000, 987654321,4)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Ahmad','V','Jabbar',987987987,'29-MAR59','980 Dallas,Houston, TX','M',25000, 987654321,4)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Joyce',NULL,'Pan',543216789,'07-FEB-78','35 S 18 E, Salt Lake City, UT','F',70000, NULL,2)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Doug','E','Gilbert',554433221,'09-JUN-60','11 S 59 E, Salt Lake City, UT','M',80000, NULL,3)

;
insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Franklin','T','Wong',333445555,'08-DEC-45','638 Voss,Houston, TX','M',40000,554433221,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Jennifer','S','Wallace',987654321,'20-JUN-31','291 Berry,Bellaire, TX','F',43000,554433221,4)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('John','B','Smith',123456789,'09-JAN-55','731 Fondren,Houston, TX','M',30000,333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Ramesh','K','Narayan',666884444,'15-SEP-52','975 Fire Oak,Humble, TX','M',38000,333445555,5)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Joyce','A','English',453453453,'31-JUL-62','5631 Rice,Houston, TX','F',25000, 333445555,5)


;

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('James','E','Borg',888665555,'10-NOV-27','450 Stone,Houston, TX','M',55000, 543216789,1)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Alica','J','Zelaya',999887777,'19-JUL-58','3321 Castle,Spring, TX','F',25000, 987654321,4)

insert into employee

(firstname,midname,lastname,ssn,birthday,address,sex,salary,supervisorssn,departmentnumber)
values

('Ahmad','V','Jabbar',987987987,'29-MAR59','980 Dallas,Houston, TX','M',25000, 987654321,4)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectA', 3388,


'Houston',1)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectB',1945, 'Salt


Lake City',3)

;
insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectC', 6688,


'Houston',5)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectD', 2423,


'Bellaire',4)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectE', 7745,


'Sugarland',5)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectF', 1566, 'Salt


Lake City',3)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectG', 1234, 'New


York',2)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectH',3467,


'Stafford',4)

;
insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectI',4345,


'Chicago',1)

insert into projects

( projectname, projectnumber, projectlocation, departmentnumber) values ('ProjectJ',2212, 'San


Francisco',2)

insert into dept_locations

(departmentnumber, departmentlocation) values

(1,'Houston')

insert into dept_locations

(departmentnumber, departmentlocation) values

(1,'Chicago')

insert into dept_locations

(departmentnumber, departmentlocation) values

(2,'New York')

insert into dept_locations

(departmentnumber, departmentlocation) values


(2,'San Francisco')

insert into dept_locations

(departmentnumber, departmentlocation) values

(3,'Salt Lake City')

insert into dept_locations

(departmentnumber, departmentlocation) values

(4,'Stafford')

insert into dept_locations

(departmentnumber, departmentlocation) values

(4,'Bellaire')

insert into dept_locations

(departmentnumber, departmentlocation) values

(5,'Sugarland')

insert into dept_locations

(departmentnumber, departmentlocation) values

(5,'Houston')

;
select * from projects

insert into works_on

(employeessn, projectnumber, hours) values

('123456789',3388,32.5)

insert into works_on

(employeessn, projectnumber, hours) values

('123456789',1945,7.5)

insert into works_on

(employeessn, projectnumber, hours) values

('666884444',3388,40.0)

insert into works_on

(employeessn, projectnumber, hours) values

('453453453',7745,20.0)

insert into works_on

(employeessn, projectnumber, hours) values

('453453453',2212,20.0)
;

insert into works_on

(employeessn, projectnumber, hours) values

('333445555',7745,10.0)

insert into works_on

(employeessn, projectnumber, hours) values

('333445555',6688,10.0)

insert into works_on

(employeessn, projectnumber, hours) values

('333445555',4345,35.0)

insert into works_on

(employeessn, projectnumber, hours) values

('333445555',2212,28.5)

insert into works_on

(employeessn, projectnumber, hours) values

('999887777',1234,11.5)

;
insert into works_on

(employeessn, projectnumber, hours) values

('999887777',1234,13.0)

insert into works_on

(employeessn, projectnumber, hours) values

('543216789',2212,17.0)

insert into works_on

(employeessn, projectnumber, hours) values

('554433221',1945,21.5)

ALTER TABLE dependents

RENAME COLUMN departmentname TO dependentname

insert into dependents

(employeessn, dependentname, sex, birthday, relationship) values

('333445555','Alice','F','05-APR-76','Daughter')

insert into dependents

(employeessn, dependentname, sex, birthday, relationship) values

('333445555','Theodore','M','25-OCT-73','Son')
;

insert into dependents

(employeessn, dependentname, sex, birthday, relationship) values

('333445555','Joy','F','03-MAY-48','Spouse')

insert into dependents

(employeessn, dependentname, sex, birthday, relationship) values

('987654321','Abner','M','29-FEB-32','Spouse')

insert into dependents

(employeessn, dependentname, sex, birthday, relationship) values

('123456789','Alice','F','31-DEC-78','Daughter')

insert into dependents

(employeessn, dependentname, sex, birthday, relationship) values

('123456789','Elizabeth','F','05-MAY-57','Spouse')

insert into employee values

('Robert', 'F', 'Scott', '943775543', '21-JUN-42', '2365 Newcastle Rd, Bellaire, TX', M, 58000,
'888665555', 1 )

insert into employee


(firstname,midname,lastname,ssn,birthday,

address,sex,salary,supervisorssn,departmentnumber) values

('Robert', 'F', 'Scott', '943775543', '21-JUN-42',

'2365 Newcastle Rd, Bellaire, TX', 'M', 58000, '888665555', 1 )

insert into works_on values

( '677678989', null, '40.0' )

insert into dependents values

( '453453453', 'John', 'M', '12-DEC-60', 'Spouse' )

delete from works_on

where employeessn = '333445555'

UPDATE department

SET managerssn = '123456789', startdate = '01-OCT-88'

WHERE departmentnumber=5

UPDATE department

SET managerssn = '123456789', managestartdate = '01-OCT-88'

WHERE departmentnumber=5

;
alter table employee

drop constraint chk_suprssn

alter table employee

add CONSTRAINT chk_suprssn FOREIGN KEY (supervisorssn) REFERENCES employee(ssn) ON DELETE


SET NULL

alter table projects

add constraint unique_pname UNIQUE (projectname)

alter table projects

modify sex char(1) not null

alter table projects

add constraint unique_pname UNIQUE (projectname)

alter table employee

modify sex char(1) not null

alter table projects

-- add constraint unique_pname UNIQUE (projectname)

;
alter table employee

modify sex char(1) not null

alter table employee

add constraint chk_address

CHECK (('door no','street','city','state','continent') in address)

alter table employee

modify salary number(7) NOT NULL

You might also like