0% found this document useful (0 votes)
4 views7 pages

COSC 51023 - Worksheet 01

Uploaded by

kushaniii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

COSC 51023 - Worksheet 01

Uploaded by

kushaniii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COSC 51023 – Advanced Database Management Systems

Work Sheet 01
1. Create the following four Relations for the database using create table statements.

PNO PNAME PRICE COLOR WEIGHT CITY

P1 NUT 20.00 RED 12 COLOMBO

P2 BOLT 14.00 GREEN 17 KANDY

P3 SCREW 14.00 BLUE 17 MATARA

P4 SCREW 11.00 RED 14 COLOMBO

P5 CAM 150.00 BLUE 12 KANDY

P6 COG 12.00 RED 19 COLOMBO

JNO JNAME CITY

J1 SORTER KANDY

J2 PUNCH MATARA

J3 READER JAFFNA

J4 CONSOLE JAFFNA

J5 COLLATOR COLOMBO

J6 VIDEO GALLE

J7 TAPE COLOMBO

SNO SNAME STATUS CITY

S1 SAMAN 20 COLOMBO

S2 JAGATH 10 KANDY

S3 ANIL 30 KANDY

S4 GAMINI 20 COLOMBO

S5 BALA 30 JAFFNA
SPJ

SNO PNO JNO QTY

S1 P1 J1 200

S1 P2 J4 700

S2 P3 J2 200

S2 P3 J3 200

S2 P3 J4 500

S2 P3 J5 600

S2 P3 J6 400

S2 P3 J7 800

S2 P5 J2 100

S3 P3 J3 200

S3 P4 J4 500

S4 P2 J1 300

S4 P2 J4 300

S5 P1 J2 1000

S5 P2 J2 200

S5 P2 J4 100

S5 P3 J4 1200

S5 P4 J4 800

S5 P5 J4 400

S5 P5 J5 500

S5 P5 J7 100

S5 P6 J2 200

S5 P6 J4 500
2. First, work by yourselves, then check with the below answers (there can be slight
differences than below answers).

Create Table Statements:

CREATE TABLE S

(Sno CHAR(2) NOT NULL,

SNAME VARCHAR(20),

STATUS NUMBER,

CITY VARCHAR(15));

CREATE TABLE P

(Pno CHAR(2) NOT NULL,

PNAME VARCHAR(20),

PRICE NUMBER,

WEIGHT NUMBER,

COLOUR VARCHAR(5),

CITY VARCHAR(15));

CREATE TABLE J

(Jno CHAR(2) NOT NULL,

JNAME VARCHAR(20),

CITY VARCHAR(15));

CREATE TABLE SPJ

(Sno CHAR(2) NOT NULL,

Pno CHAR(2) NOT NULL,

Jno CHAR(2) NOT NULL,

Quantity NUMBER);

Insert into S values('S1', 'SAMAN', 20, 'COLOMBO');


Insert into S values('S2', 'JAGATH', 10, 'KANDY');

Insert into S values('S3', 'ANIL', 30, 'KANDY');

Insert into S values('S4', 'GAMINI',20, 'COLOMBO');

Insert into S values('S5', 'BALA', 30, 'JAFFNA');

Insert into J values('J1', 'SORTER', 'KANDY');

Insert into J values('J2', 'PUNCH', 'MATARA');

Insert into J values('J3', 'READER', 'JAFFNA');

Insert into J values('J4', 'CONSOLE', 'JAFFNA');

Insert into J values('J5', 'COLLATOR', 'COLOMBO');

Insert into J values('J6', 'VIDEO', 'GALLE');

Insert into J values('J7', 'TAPE', 'COLOMBO');

Insert into SPJ values('S1', 'P1', 'J1', 200);

Insert into SPJ values('S1', 'P2', 'J4', 700);

Insert into SPJ values('S2', 'P3', 'J2', 200);

Insert into SPJ values('S2', 'P3', 'J3', 200);

Insert into SPJ values('S2', 'P3', 'J4', 500);

Insert into SPJ values('S2', 'P3', 'J5', 600);

Insert into SPJ values('S2', 'P3', 'J6', 400);

Insert into SPJ values('S2', 'P3', 'J7', 800);

Insert into SPJ values('S2', 'P5', 'J2', 100);

Insert into SPJ values('S3', 'P3', 'J3', 200);

Insert into SPJ values('S3', 'P4', 'J4', 500);

Insert into SPJ values('S4', 'P2', 'J1', 300);

Insert into SPJ values('S4', 'P2', 'J4', 300);

Insert into SPJ values('S5', 'P1', 'J2', 1000);

Insert into SPJ values('S5', 'P2', 'J2', 200);

Insert into SPJ values('S5', 'P2', 'J4', 100);

Insert into SPJ values('S5', 'P3', 'J4', 1200);

Insert into SPJ values('S5', 'P4', 'J4', 800);


Insert into SPJ values('S5', 'P5', 'J4', 400);

Insert into SPJ values('S5', 'P5', 'J5', 500);

Insert into SPJ values('S5', 'P5', 'J7', 100);

Insert into SPJ values('S5', 'P6', 'J2', 200);

Insert into SPJ values('S5', 'P6', 'J4', 500);

Insert into P(Pno, Pname, Price, COLOUR, Weight, City) values('P1', 'NUT', 20, 'RED', 12, 'COLOMBO');

Insert into P values('P2', 'BOLT', 14, 'GREEN', 17, 'KANDY');

Insert into P values('P3', 'SCREW', 14, 'BLUE', 17, 'MATARA');

Insert into P values('P4', 'SCREW', 11, 'RED', 14, 'COLOMBO');

Insert into P values('P5', 'CAM', 150, 'BLUE', 12, 'KANDY');

Insert into P values('P6', 'COG', 12, 'RED', 19, 'COLOMBO');

3. Now attempt the following queries.


i. Get part numbers for all parts.
ii. Get the supplier number, name, status and location of all suppliers.
iii. Get the part numbers for all parts currently being supplied.
iv. Get supplier numbers for suppliers in Kandy with >20 status value
v. Get suppliers whose location is known, i.e. not null
vi. Find the parts which are located in Colombo and has weight greater than 15.
vii. Find the suppliers who have status values between 10 and 20.
viii. Get the details of suppliers who are either located in Colombo or in Jaffna
ix. For each part in Colombo get the name and its weight in Kilograms
x. Get the supplier number and the status for suppliers in Kandy, in descending order of
the status
xi. Get all suppliers whose name has ‘A’ as its second character.
xii. Retrieve the part names that start with letter C
xiii. Retrieve the surnames of suppliers whose name begin with any vowels.
xiv. Retrieve the surnames of suppliers whose name begin with any letter A to P.
xv. Retrieve the surnames of suppliers who have an even number as the first character of
their status
xvi. Get the total number of suppliers.
xvii. Get the total number of suppliers currently supplying parts
xviii. Find the maximum and minimum weight of parts.
xix. Find the number of shipments for part P2.
xx. Find the average price of parts located in Colombo.
xxi. Get the average price of the parts which are in all cities other than ‘Matara’.
xxii. For each part currently being supplied, get the part number and the total quantity
supplied for that part
xxiii. For each supplier and each part, get the total quantity supplied of this part by this
supplier
xxiv. For each part supplied, get the number of suppliers currently supplying that part
xxv. For each part supplied, get the number of shipments of that part
xxvi. For each supplier and each part, get the number of projects that the supplier is currently
supplying the part to
xxvii. Get the part numbers for all parts supplied in more than one shipment
xxviii. Calculate the average weight of the parts located in Colombo and located in Kandy.
xxix. For each part s.t. the total quantity supplied is greater than 1000, get the part number
and the maximum quantity of that part supplied.
xxx. For the above query, order the result in increasing quantity value.
xxxi. For the above query exclude all the shipments which has quantity less than 200.
xxxii. For each part supplied, get part number and names of all cities supplying the part.
xxxiii. Get all (part name, project name) pairs such that the part and the project in question are
located in the same city
xxxiv. Get all info about the (supplier, part) pairs where the supplier and part concerned are
located in the same city, but omitting suppliers with status less than 20
xxxv. Get all supplier/supplying information of those suppliers with status value less than 20,
and the quantity supplied greater than 200
xxxvi. The value of a shipment is obtained from the price of the part being supplied, and the
quantity. For each shipment, get the supplier number, part number, project number,
and the value of the shipment.
xxxvii. Get all pairs of city names such that a supplier located in the first city is currently
supplying a part stored in the second city
xxxviii. Get all pairs of supplier numbers such that the two suppliers concerned are located in
the same city
xxxix. Get supplier names for suppliers who supply part P2
xl. Get supplier numbers for suppliers who are located in the same city as supplier S1
xli. Get supplier names for suppliers who are not currently supplying part P2
xlii. Get the part numbers for all parts in Colombo that are supplied in more than one
shipment
xliii. Get supplier names for suppliers who supply at least one part where the weight is less
than 15.
xliv. Get supplier numbers of suppliers whose status value is less than the current maximum
status value.
xlv. Get supplier names for suppliers who supply part P2
xlvi. Get the supplier numbers for suppliers with status value less than at least the current
maximum status value in the S table
xlvii. Get the suppliers with the lowest status value.
xlviii. Get the part number of parts that are currently supplied s.t. the quantity supplied to all
projects is greater than 100.
xlix. Get supplier names for suppliers who supply part P2 using EXISTS.

l. Get supplier names for suppliers who are not currently supplying part P2

li. Get the supplier names for suppliers who currently supply all parts

lii. Get the supplier name for suppliers who currently supply all parts that are supplied by
S1

liii. Get the supplier name for suppliers for whom there is some part that is not being
supplied by the supplier
liv. Get part numbers for parts that either weigh more than 18 pounds or are currently
supplied by supplier S2.

lv. Select the top seven shipments

lvi. Use alter table/ drop table/ add constraints statements

a. Delete supplier S1

b. Delete all shipments

c. Delete all shipments from suppliers in COLOMBO.

d. …

lvii. Change the price of part P2 to 15 and increase its weight by 5

lviii. Double the status of all suppliers in Colombo

lix. Set the quantity to zero for all suppliers in Colombo.

You might also like