Professional Documents
Culture Documents
CIS 4400
wiktor.kostecki@baruchmail.cuny.edu
1.
CREATE TABLE employee (
fname
minit
varchar2(1),
lname
ssn
bdate
date,
address varchar2(30),
sex
char,
salary number(10,2),
superssn char(9),
dno
number(4),
mgrstartdate date,
primary key (dnumber),
unique (dname),
foreign key (mgrssn) references employee(ssn)
);
CREATE TABLE dept_locations (
dnumber number(4),
dlocation varchar2(15),
primary key (dnumber,dlocation),
foreign key (dnumber) references department(dnumber)
);
CREATE TABLE project (
pname
pnumber
plocation varchar2(15),
dnum
number(4),
hours number(4,1),
primary key (essn,pno),
foreign key (essn) references employee(ssn),
foreign key (pno) references project(pnumber)
);
CREATE TABLE dependent (
essn
char(9),
dependent_name varchar2(15),
sex
bdate
char,
date,
relationship varchar2(8),
primary key (essn,dependent_name),
foreign key (essn) references employee(ssn)
);
ALTER TABLE employee ADD CONSTRAINT
fk_department FOREIGN KEY (dno) REFERENCES
department (dnumber);
2.
INSERT ALL
INTO employee values('John', 'B', 'Smith','123456789', '01-09-1955', '731 Fondren,
Houston,TX', 'M', 30000, '333445555', null)
INTO employee values('Franklin', 'T', 'Wong','333445555', '12-08-1945', '638 Voss,
Houston,TX', 'M', 40000, '888665555', null)
INTO employee values('Alicia', 'J', 'Zelaya','999887777', '07-19-1958', '3321 Castle,
Spring,TX', 'F', 25000,'987654321', null)
INTO employee values('Jennifer', 'S', 'Wallace','987654321', '06-20-1931', '291
Berry, Bellaire,TX', 'F', 43000, '888665555', null)
INTO employee values('Ramesh', 'K', 'Narayan','666884444', '09-15-1952', '975 Fire
Oak, Humble,TX', 'M', 38000, '333445555', null)
INTO employee values('Joyce', 'A', 'English','453453453', '07-31-1962', '5631 Rice,
Houston, TX', 'F', 25000, '333445555', null)
INTO employee values('Ahmad', 'V', 'Jabbar','987987987', '03-29-1959', '980 Dallas,
Houston,TX', 'M', 25000, '987654321', null)
INTO employee values('James', 'E', 'Borg','888665555', '11-10-1927', '450 Stone,
Houston,TX', 'M', 55000, null, null)
INTO employee values('New', 'V', 'Lost','777977977', '03-23-1977', 'NY,NY', 'M',
20000, '987654321', null)
INSERT ALL
INTO project VALUES ('ProductX', 1, 'Bellaire', 5)
INTO project VALUES ('ProductY', 2, 'Sugarland', 5)
INTO project VALUES ('ProductZ', 3, 'Houston', 5)
INTO project VALUES ('Computerization', 10, 'Stafford', 4)
INTO project VALUES ('Reorganization', 20, 'Houston', 1)
INTO project VALUES ('Newbenefits', 30, 'Stafford', 4)
SELECT * FROM dual;
INSERT ALL
INTO dept_locations VALUES (1, 'Houston')
INTO dept_locations VALUES (4, 'Stafford')
INTO dept_locations VALUES (5, 'Bellaire')
INTO dept_locations VALUES (5, 'Sugarland')
INTO dept_locations VALUES (5, 'Houston')
SELECT * FROM dual;
INSERT ALL
INTO dependent VALUES ('333445555','Alice','F','04-05-1976','Daughter')
UPDATE employee
SET dno = 5
WHERE ssn = 123456789;
UPDATE employee
SET dno = 5
WHERE ssn = 333445555;
UPDATE employee
SET dno = 4
WHERE ssn = 999887777;
UPDATE employee
SET dno = 4
WHERE ssn = 987654321;
UPDATE employee
SET dno = 5
WHERE ssn = 666884444;
UPDATE employee
SET dno = 5
WHERE ssn = 453453453;
UPDATE employee
SET dno = 4
WHERE ssn = 987987987;
UPDATE employee
SET dno = 1
WHERE ssn = 888665555;
UPDATE employee
SET dno = 4
WHERE ssn = 777977977;