Sunteți pe pagina 1din 4

Assignment No.

1
1 Supplier-Part Case Study

Consider a sample database to store the information about Supplier, Parts and quantity
supplied by the suppliers. The database consists of three tables S, P and SP.

Table S (Supplier table) contains the information about the suppliers and having following
fields:

Sno - Supplier number of supplier that is unique


Sname-Supplier name
City - City of the supplier
Status - Status of the city e.g. A grade cities may have status 10, B grade cities may have
status 20 and so on.

Table P (Part table) contains the information about the parts and having following fields:

Pno - Part number of parts that is unique


Pname - Part name
Color - Color of the part
City - City in which the part manufactures.

Table SP (Shipment table) contains the following attributes:


Sno -- Supplier number of the supplier
Pno -- Part number supplied by supplier
Qty -- Quantity supplied by supplier for a particular part number

1.1 Exercise on Creation of Table


Create the following table with mentioned constraints:

S Table
Column Data Type Width Constrains
Name
Sno Varchar2 5 Primary Key
Sname Varchar2 20 Unique
City Varchar2 20 City must be New Delhi, Patiala, Amritsar
and Qadian
Stauts Number 3 Must be grea/ter than 10

P Table
Column Data Type Width Constrains
Name
Pno Varchar2 5 Primary Key
Pname Varchar2 20 Unique
Color Varchar2 20 Not Null
City Varchar2 20 City must be Jalandhar, Patiala, Amritsar
and Qadian
SP Table
Column Data Type Width Constrains
Name
Sno Varchar2 5 Refers Sno of Supplier table
Pno Varchar2 5 Refers Pno of Part table
Qty Number 4 Must be greater than 100

Identify the primary key of SP table and apply Primary constraint on that.

1.2 Exercise on Alter Table

1. List all the constraints available on P table


2. Drop the check constraints on P table
3. Add column date_of_shipment into SP table.
4. Drop column date_of_shipment
5. Drop foreign key constraint on SP table and add with the help of alter table option.
6. Change the width of Pname column.
7. Apply foreign key constraint on SP table.

1.3 Exercise on Insertion of records

Insert the following record by using substitutional variables

S Table
SNO NAME CITY STATUS
S1 SUNEET QADIAN 20
S2 ANKIT AMRITSAR 10
S3 AMIT PATIALA 30

P Table
PNO NAME COLOR CITY
P1 NUT RED QADIAN
P2 BOLT GREEN AMRITSAR
P3 SCREW BLUE JALANDHAR
P4 SCREW RED QADIAN

SP Table
SNO PNO QTY
S1 P1 250
S1 P2 300
S1 P3 500
S2 P1 250
S2 P2 500
S3 P2 300

1. Check the working of all the constraints by inserting the invalid data in the corresponding
columns.

2. Note down the errors encountered.


1.4 Exercise on Creation of table with the use of existing table

1. Create a duplicate copy of S table.


2. Copy the structure of P table.
3. Copy all the record of parts having color red in another table with different column
headings.

1.5 Exercise on Renaming of table

1. Rename table duplicate table of S.

1.6 Exercise on Simple data retrieval

1. Get part number of all parts supplied.


2. Get full details of suppliers.
3. Get supplier numbers for suppliers in Qadian with status>20.
4. Get Supplier numbers and status for suppliers whose name starts with A , in descending
order of status.
5. Get Supplier number supplying qty between 100 and 300.
6. Get the names of the green parts.
7. Get the name and status for every supplier that is not in Qadian, Amritsar.
8. Get the part numbers that are supplied by S1.

9. Get the Part number and Qty are supplied by P1.

1.7 Exercise on Complex data retrieval

1. For each part supplied get part number and names of all cities supplying the part.
2. Get Qty supplied for Red parts.
3. Get Sname supplying Red part.
4. Get Sname, Pname who supply qty more than 100.
5. Get all pairs of suppliers numbers such that the two suppliers are located in the same
city.
6. Get Sname for suppliers who supply part P2.
7. Get Supplier numbers for suppliers who supply at least one part supplied by supplier S2.
8. Get supplier names for suppliers who do not supply part P2.
9. Get suppliers numbers for suppliers who are located in same city as supplier S1.

1.8 Exercise based on Built in functions and group by expression

1. Get the total number of suppliers.


2. Get total number of suppliers currently supplying parts.
3. Get the number of shipment for part P3.
4. Get the total quantity of part P2 supplied.
5. Get Supplier number whose status value is maximum.
6. For each part supplied, get the part number and the total quantity supplied of that part.
7. Get total Quantity supplied by suppliers of Qadian.
8. Get part number for all parts supplied by more than one supplier.
9. Get part name of supplier who more than 5 parts excluding the suppliers of Amritsar.
10. Get supplier name of who supply more than 10 parts excluding the part of red colors;
display the output in descending order.
1.9 Exercise on Updation of database

1. Change the name of color red to black.


2. Change the color of part P2 to yellow and set its city to “unknown”.
3. Double the Qty of all the parts supplied.
4. Set the quantity to zero for all the suppliers in Amritsar.
5. Change the supplier number S2 to S4.
1.10 Exercise on Deletion of database

1. Delete all shipments


2. Delete all shipments from suppliers in “Patiala”
3. Delete P table

1.11 Exercises on Drop Option

Drop all the tables created by using existing table.

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