Documentation CSC675 Project
Documentation CSC675 Project
CSC 675
/*Question 1.*/
/*2.*/
SElect e.name
From Employee e, Project p
where e.ssn = p.ssn AND p.dname = 'Toy';
/*3.*/
/*4.*/
select d.dept_name
2
From Dept d, Project p, Works_for w, Employee e
Where d.dcode = p.dcode AND p.dno = w.dno AND w.ssn = e.ssn AND e.name = 'Psmith' AND
e.name = 'Pwong';
/*5.a*/
select d.dept_name
From Dept1 d, Project p, Works_for w, Employee e
Where d.dcode = p.dcode AND w.dno = p.dno AND w.ssn = e.ssn AND e.name = 'Psmith'
UNION
select d2.dept_name
From Dept1 d2, Project p2, Works_for w2, Employee e2
Where d2.dcode = p2.dcode AND w2.dno = p2.dno AND w2.ssn = e2.ssn AND e2.name =
'Pwong';
/*5b.*/
/*
6.b
*/
select distinct d.dept_name
From Dept1 d
Where d.dcode IN (SELECT p.dcode
From Project p
Where p.ssn IN (Select e.ssn
From Employee e
Where e.name = 'Psmith'));
/*10*/
select e.name
From Employee e, Works_for w, Project p, Dept1 d
Where d.dcode = p.dcode AND p.dno = w.dno AND w.ssn = e.ssn AND d.dept_name = 'Toy'
UNION
select e2.name
From Employee e2, Works_for w2, Project p2, Dept1 d2
Where d2.dcode = p2.dcode AND p2.dno = w2.dno AND w2.ssn = e2.ssn AND d2.dept_name =
'Shoes';
/*12*/
select e.name
From Employee e, Works_for w
Where e.ssn = w.ssn AND w.percent_time = (Select MAX(w2.percent_time)
From Works_for w2);
SElect e.name
From Employee e, Project p
where e.ssn = p.manager_ssn AND p.dname = 'Toy';
Select p.dname
3
From Project p, Employee e, Works_for w
Where p.manager_ssn = e.ssn AND e.ssn = w.ssn AND w.percent_time >= '50%' ;
select d.dept_name
From Dept d, Project p, Works_for w, Employee e
Where d.dcode = p.housed_dcode AND p.dno = w.dno AND w.ssn = e.ssn AND e.name =
'Psmith' AND e.name = 'Pwong';
select d.dept_name
From Dept d, Project p, Works_for w, Employee e
Where d.dcode = p.housed_dcode AND w.dno = p.dno AND w.ssn = e.ssn AND e.name = 'Psmith'
UNION
select d2.dept_name
From Dept d2, Project p2, Works_for w2, Employee e2
Where d2.dcode = p2.housed_dcode AND w2.dno = p2.dno AND w2.ssn = e2.ssn AND e2.name =
'Pwong';
select e.name
From Employee e, Works_for w, Project p, Dept d
Where d.dcode = p.housed_dcode AND p.dno = w.dno AND w.ssn = e.ssn AND d.dept_name =
'Toy'
UNION
select e2.name
From Employee e2, Works_for w2, Project p2, Dept d2
Where d2.dcode = p2.housed_dcode AND p2.dno = w2.dno AND w2.ssn = e2.ssn AND
d2.dept_name = 'Shoes';
select e.name
From Employee e, Works_for w
Where e.ssn = w.ssn AND w.percent_time = (Select MAX(w2.percent_time)
From Works_for w2);
4
insert into Dept values ('123','Toy','sf');
insert into Dept values ('234', 'Food','la');
insert into Dept values ('456','Bird','sf');
insert into Dept values ('789', 'Food', 'sf');
insert into Dept values ('222', 'Shoes', 'ny');
5
select * from Works_for;
…………………
SQL> @s;
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
6 rows selected.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
8 rows selected.
SQL>
………………………..
DNO DNAME
--- --------------------
4 Shoes
NAME
--------------------
Smith
DNAME
--------------------
Food
Toys
Shoes
Shoes
Shoes
no rows selected
DEPT_NAME
--------------------
Bird
Food
Shoes
Toy
no rows selected
DEPT_NAME
--------------------
Shoes
NAME
--------------------
Psmith
Pwong
Smith
8
NAME
--------------------
Mary
Psmith
Psmith
SQL>
……………………….
Note: Some queries does not give any output as there is no match, such as “fnd the names of
departments that house a project employing "Psmith" and "Pwong" as Psmith and Pwong is not employed in
same project.
222
Shoes
ny
234
Food
la
456
Bird
sf
789
Food
sf
NULL
NULL
NULL
9
123456777
Jake
510222888
8
Bird
Departmen
t
123456788
Mary
415688900
0
Food
Departmen
t
123456789
Smith
510222888
8
Toy
Departmen
t
123456799
John
510527446
5
Bird
Departmen
t
666666666
Pwong
415222333
3
Toy
Departmen
t
999999999
Psmith
415338171
9
Shoe
Departmen
t
NULL
NULL
NULL
NULL
10
Table Project Table Works_for
Dno Dname Phone Ssn Dcode Dno Dname ssn Percent_time
1
Toy
12345
6789
100%
2
Food
12345
6788
80%
3
Bird
66666
6666
70%
4
Shoes
99999
9999
40%
5
Toy
66666
6666
60%
NULL
NULL
NULL
NULL
11
1
Toy
51041
56889
12345
6789
123
2
Food
41533
81111
12345
6788
234
3
Bird
41533
82222
12345
6799
456
4
Shoes
51034
56778
99999
9999
222
5
Toy
51041
56889
66666
6666
123
NULL
NULL
NULL
NULL
NULL
12
After that, I have executed the first query, which is “find the dno’s and dname’s of all projects that employees
named ‘Psmith’ work on”. I execute the query by executing DisplayEmployee.java file and I get the following
resultant applet:
Above is the applet output which shows the dno and dname where Psmith works.
The output of VBScript can also go to a text file; please see the attached hw7_script.vbs and fsoutput.txt at
home-work folder.
13