Sunteți pe pagina 1din 2

COP 3540 SPRING 2011

assig2.doc
ASSIGNMENT #2
DUE DATE: February 24

Start by creating your database, called yourusername_spjdatabase,


on dbw using Visual Studio 2010 Server Explorer. Then create and
load in a Visual Studio 2010 Database Project called
yourusername_assig2 (in a Solution called yourusername_assig,
contained in a Solution Directory called yourusername_assig2) the
S, P, J, and SPJ tables, using the SQL script in
createSqlServer.doc. Your tables MUST have EXACTLY these records
when you run the below SQL scripts.

Put a SQL script in your yourusername_assig2 Database Project,


for each of the below queries, that contains the select statement
which expresses that query, Make sure that you precede each
select statement with a comment that provides the problem number
for the select statement (e.g., /* Problem 1(a) */). Execute each
such script, and place a screen shot that shows both the SQL
script contents and the result of the execution (as on p.27 of
databaseprojects.doc) in your .doc file for this assignment (you
must also paste a copy of the SQL Script contents, below the
screen shots). Also place on the top of your .doc file, your
database name, SQL Server user name, and SQL Server password.

Upload your .doc file to Blackboard, as in Assignment #1.


Also, zip your Solution Directory yourusername_assig2 and upload
it to Blackboard, as in Assignment #1.

(1) Print the P# and CITY of each Red part that has weight > 13.
My Answer:
Select p#, city From p where Weight > 13 AND Color =’Red’

(2) Print the P#s of parts that are supplied by a London


supplier to a Paris project
My Answer: Select p# from spj where spj.s# in (Select S.s#
From s where s.city = ‘London’) AND spj.j# in (Select j.j#
where j.city = ‘Paris’)

Do this query two ways: (a) as a flat select, and (b)


completely nested, i.e., using subqueries so as to avoid all
JOIN clauses.

(3) Print the pairs of J#s such that there is a shipment for
each project in the pair involving the same part and having
QTY > 200.

My Answer: Select J# from SPJ where qty > 200 group by p#,
j#

NOTE: In Problem (3) do not print any records of the


form (x,x). In addition, if (x,y) is printed
not also print (y,x). Also, do not print
duplicate records (i.e., make sure that no
record is printed more than once).

(4) (a) Print the J#s of projects that are supplied with a Nut
and are also supplied with a London part.
My Answer: Select spj.j# from spj where spj.p# in (select
p.p# from where p.name=’Nut’ AND p.city=’London’)

(b) Print the J#s of projects that are supplied with a Nut
but are not supplied with a London part.
My Answer: Select spj.j# from spj where spj.p# in (select
p.p# from where not (p.name=’Nut’ AND p.city=’London’))

(5) Print the J#s of projects that are not supplied with a
part that has weight > 17.
My Answer: (Select j# from spj) except select spj.j# from
spj,p where p.weight > 17

WARNING: You cannot use the following operators in this


assignment: NOT IN, <>, !=, <=

S-ar putea să vă placă și