Professional Documents
Culture Documents
ROLL NO—21/1278
PAPER- DATABASE MANAGEMENT SYSTEM
PRACTICAL QUESTIONS
QUESTION 1.
Create a database having two tables with the specified fields, to computerize a
library system of a Delhi University College.
LibraryBooks (Accession number, Title, Author, Department, PurchaseDate,
Price)
IssuedBooks (Accession number, Borrower)
mysql>create database lib;
Database changed
mysql> create table Library_Books(Acc_No int, Title varchar(38), Author varchar(38), Department
varchar(38),Purchase_Date date, Price int)
-> ;
+---------------+-------------+------+-----+---------+-------+
+---------------+-------------+------+-----+---------+-------+
+---------------+-------------+------+-----+---------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------+
| Acc_No | Borrower |
+--------+----------+
| 1212 | Disha |
| 1213 | Vidya |
| 1210 | Asha |
| 1209 | Meena |
| 1211 | Shee |
+--------+----------+
B))
Delete the record of book titled “Database System Concepts”.
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
C))
CHANGE THE DEPARTMENT OF THE BOOK TITLED “DTATABASE MANAGEMENT
CONCEPTS”.
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
+--------+----------------------------+-------------------+------------+---------------+-------+
D))
LIST ALL BOOKS THAT BELONG TO “CS” DEPARTMENT.
mysql> select * from Library_Books where Department="CS";
+--------+----------------------------+------------+------------+---------------+-------+
+--------+----------------------------+------------+------------+---------------+-------+
+--------+----------------------------+------------+------------+---------------+-------+
E)) LIST ALL BOOKS THAT BELONG TO “CS” DEPARTMENT AND ARE
WRITTEN BY AUTHOR “NAVATHE”.
+--------+----------------------------+---------+------------+---------------+-------+
+--------+----------------------------+---------+------------+---------------+-------+
+--------+----------------------------+---------+------------+---------------+-------+
mysql> select title from Library_Books as lb, Issued_Books as ib where Department="CS" and
lb.Acc_No=ib.Acc_No;
+----------------------------+
| title |
+----------------------------+
| discrete maths |
+----------------------------+
QUESTION2
Database changed
mysql> create table AAI(clg_roll varchar(3), paper_code varchar(3), attendance int, marks int, constraint
FK1 Foreign Key(clg_roll) references PI(clg_roll), Constraint FK2 Foreign Key(paper_code) references
paper_details(paper_code), primary key(clg_roll,paper_code));
+----------+--------------+------+-----+---------+-------+
+----------+--------------+------+-----+---------+-------+
+----------+--------------+------+-----+---------+-------+
+------------+------------+------+-----+---------+-------+
+------------+------------+------+-----+---------+-------+
+------------+------------+------+-----+---------+-------+
+------------+--------------+------+-----+---------+-------+
+------------+--------------+------+-----+---------+-------+
+------------+--------------+------+-----+---------+-------+
+----------+-------+------------+---------+-------+------------+
+----------+-------+------------+---------+-------+------------+
+----------+-------+------------+---------+-------+------------+
+------------+------------------------------+
| paper_code | paper_name |
+------------+------------------------------+
| P1 | Introduction of Computers |
| P3 | Database System |
| P4 | Computer Networks |
| P5 | MultiMedia System |
+------------+------------------------------+
5 rows in set (0.00 sec)
+------------+------------+------+-----+---------+-------+
+------------+------------+------+-----+---------+-------+
+------------+------------+------+-----+---------+-------+
+----------+------------+------------+-------+
+----------+------------+------------+-------+
|1 | P1 | 75 | 87 |
|1 | P2 | 67 | 89 |
|1 | P4 | 80 | 67 |
|2 | P2 | 87 | 78 |
|2 | P5 | 85 | 76 |
|3 | P1 | 77 | 59 |
|3 | P3 | 90 | 90 |
|4 | P2 | 79 | 69 |
|4 | P4 | 84 | 88 |
|5 | P2 | 68 | 55 |
|5 | P3 | 54 | 58 |
+----------+------------+------------+-------+
B))
DESIGN A QUERY THAT WILL RETURN THE RECORDS ALONG WOTH THE NAME
OF THE STUDENT FROM THE FIRST TABLE, RELATED TO STUDENTS WHO HAVE
MORE THAN 75% ATTENDANCE AND MORE THAN 60%MARKS IN PAPER2.
mysql> select P.*, I.name from paper_details as P, PI as I, AAI as V where I.clg_roll=V.clg_roll and
P.paper_code=V.paper_code and V.attendance>75 and V.marks>60 and P.paper_code="P2";
+------------+------------------------------+-------+
+------------+------------------------------+-------+
+------------+------------------------------+-------+
mysql> select I.name, V.marks as PI_marks, I.address from paper_details as P, PI as I, AAI as V where
I.clg_roll=V.clg_roll and P.paper_code=V.paper_code and I.address="Delhi" and V.marks>60 and
P.paper_code="P1";
+-------+----------+---------+
+-------+----------+---------+
| Heena | 87 | Delhi |
+-------+----------+---------+
D))
FIND THE TOTAL ATTENDANCE AND TOTAL MARKS OBTAINED BY
EACH STUDENT.
+----------+-------+------------+-----------------+
+----------+-------+------------+-----------------+
+----------+-------+------------+-----------------+
E))
LIST THE NAME OF STUDENT WHO HAS GOT THE HIGHEST MARKS IN
PAPER2.
+----------+-------+---------------+
+----------+-------+---------------+
|1 | Heena | 89 |
+----------+-------+---------------+
QUESTION3.
Create the following tables and answer the queries given below:
Customer (CustID, email, Name, Phone, ReferrerID) Bicycle (BicycleID,
DatePurchased, Color, CustID, ModelNo) BicycleModel (ModelNo,
Manufacturer, Style) Service (StartDate, BicycleID, EndDate)
mysql> create table Customer(CustID varchar(30), email varchar(30), Name varchar(40), Phone
varchar(40),ReferrerID varchar(30));
+--------+-------------------+--------+------------+------------+
+--------+-------------------+--------+------------+------------+
+--------+-------------------+--------+------------+------------+
+-----------+---------------+--------+--------+---------+
+-----------+---------------+--------+--------+---------+
+-----------+---------------+--------+--------+---------+
+---------+--------------+---------------+
+---------+--------------+---------------+
+---------+--------------+---------------+
+------------+-----------+------------+
+------------+-----------+------------+
| 2022-01-03 | B1 | 2022-01-05 |
| 2021-02-06 | B1 | 2021-02-07 |
| 2021-03-16 | B2 | 2021-03-18 |
| 2022-03-13 | B6 | 2022-03-16 |
| 2022-04-20 | B4 | 2022-04-22 |
+------------+-----------+------------+
-> ;
B))
All the customers who have bikes manufactured by honda:
mysql> select distinct c.* from Customer as C, BicycleModel as BM, Bicycle as B where
C.CustID=B.CustID and B.ModelNo=BM.ModelNo and BM.Manufacturer="Honda";
+--------+-------------------+-------+------------+------------+
+--------+-------------------+-------+------------+------------+
+--------+-------------------+-------+------------+------------+
C))
Bicycles purchased by customers referred to by "C1":
mysql> select B.* from Bicycle as B, Customer as C, BicycleModel as BM where C.CustID=B.CustID and
B.ModelNo=BM.ModelNo and C.ReferrerID="C1";
+-----------+---------------+-------+--------+---------+
+-----------+---------------+-------+--------+---------+
+-----------+---------------+-------+--------+---------+
+--------------+
| Manufacturer |
+--------------+
| HONDA |
+--------------+
E))
Models of the bicycles given for service::
mysql> select distinct(bicycle.modelno), bicyclemodel.style from bicycle, service, bicyclemodel where
bicycle.bicycleid=service.bicycleid and bicycle.modelno=bicyclemodel.modelno;
+---------+---------------+
| modelno | style |
+---------+---------------+
+---------+---------------+
QUESTION 4.
Create the following tables, enter at least 5 records in each table and answer
the queries given below.
EMPLOYEE ( Person_Name, Street, City ) 11
WORKS ( Person_Name, Company_Name, Salary )
COMPANY ( Company_Name, City )
MANAGES ( Person_Name, Manager_Name )
B))
Alter table employee, add a column “email” of type varchar(20).
mysql> alter table Employee add(Email_ID varchar(255) default 'nalimsingh8@gmail.com');
C))
Find the name of all managers who work for both Samba Bank and
NCB Bank.
+------------+-------------+
| Manager_ID | Person_Name |
+------------+-------------+
| 123 | Soumya |
| 124 | Hemant |
+------------+-------------+
D))
Find the names, street address and cities of residence and salary of
employees who work for “Samba Bank” and earn more than $10,000.
mysql> select
E.Employee_ID,E.Person_Name,E.Street,E.city,W.Salary_$,C.Company_Name,C.Company_ID from
Employee as E,Works as W,Company as C where C.Company_Name='Samba Bank' and
W.Salary_$>10000 and E.Employee_ID=W.Employee_ID and C.Company_ID=W.Company_ID;
+-------------+-------------+----------+---------+----------+--------------+------------+
+-------------+-------------+----------+---------+----------+--------------+------------+
+-------------+-------------+----------+---------+----------+--------------+------------+
E))
Find the name of all employees who live in the same city as the
company for which they work.
+-------------+-------------+---------+
+-------------+-------------+---------+
+-------------+-------------+---------+
F))
Find the highest salary, lowest salary and average salary paid by each
company.
mysql> select c.Company_Name,c.Company_ID,max(w.Salary_$) as Highest_Salary,min(w.Salary_$) as
Lowest_Salary,avg(w.Salary_$) as Average_Salary from Company as c,Works as w where
c.Company_ID=w.Company_ID group by c.Company_ID;
+--------------+------------+----------------+---------------+----------------+
+--------------+------------+----------------+---------------+----------------+
+--------------+------------+----------------+---------------+----------------+
G))
Find the sum of salary and number of employees in each company.
+--------------+------------+--------------+-----------------+
+--------------+------------+--------------+-----------------+
+--------------+------------+--------------+-----------------+
h))
Find the name of the company that pays the highest salary.
+--------------+----------------+
| company_name | Highest_Salary |
+--------------+----------------+
+--------------+----------------+
QUESTION 5.
Database changed
mysql> create table suppliers (SNo char(2) primary key, SName varchar (50) not null, Status int not null,
mysql> create table Parts (PNo char(2) primary key, PName varchar (100) not null, Colour varchar (50)
not
-> null, Weight_kg int not null, PCity varchar(50) not null);
mysql> create table Project (JNo char(2) primary key, JName varchar (100) not null, JCity varchar (50)
not
-> null);
mysql> create table Shipment(SNo char(2) not null, PNo char(2) not null, JNo char(2) not null, Quantity
int not null, constraint Ft1 foreign key(SNo) references Suppliers(SNo) on delete cascade on update
cascade, constraint Ft2 foreign key(PNo) references Parts(PNo) on delete cascade on update cascade,
constraint FJ foreign key(JNo) references Project(JNo) on delete cascade on update cascade, primary
key(Sno, PNo, JNo));
+-----+-------------+--------+--------+----------+
+-----+-------------+--------+--------+----------+
select distinct(S.Sname), P.Pname, Pj.Jname from Parts as P, Project as Pj, Suppliers as S, Shipment as Sh
where Sh.Sno=S.Sno and P.Pno=Sh.Pno and Sh.Jno=Sh.Jno;
+-----+--------+--------+----------+
+-----+--------+--------+----------+
| 1 | Mori | 36 | Paris |
| 2 | Shori | 20 | London |
| 3 | Chhori | 22 | Paris |
| 5 | Nori | 12 | Berlin |
+-----+--------+--------+----------+
+-----+----------+----------+
+-----+----------+----------+
| J1 | Machines | London |
| J2 | Sano | Paris |
| J4 | Shona | Berlin |
| J5 | Rona | Paris |
+-----+----------+----------+
+------+------+------+----------+
+------+------+------+----------+
| S1 | P1 | J2 | 500 |
| S2 | P3 | J3 | 400 |
| S2 | P4 | J1 | 750 |
| S5 | P2 | J5 | 200 |
| S1 | P2 | J4 | 360 |
+------+------+------+----------+
b))
Get supplier numbers for suppliers in Paris with status>20.
+-----+
| Sno |
+-----+
| S1 |
| S3 |
+-----+
c))
Get suppliers details for suppliers who supply part P2. Display the
supplier list in increasing order of supplier numbers.
mysql> select distinct S.* from Suppliers as S, Parts as P, Shipment as Sh where Sh.PNo="P2" and
S.Sno=Sh.Sno and P.Pno=Sh.Pno order by S.Sno;
+-----+-------+--------+----------+
+-----+-------+--------+----------+
| S1 | MORI | 36 | PARIS |
| S5 | NORI | 12 | BERLIN |
+-----+-------+--------+----------+
d))
Get suppliers names for suppliers who do not supply part P2
mysql> Select * from suppliers where SNo not in(Select distinct S.Sno from suppliers s, shipment h
where
+-----+--------+--------+----------+
+-----+--------+--------+----------+
| S2 | SHORI | 20 | LONDON |
| S3 | CHHORI | 22 | PARIS |
| S6 | LORI | 25 | LONDON |
| S7 | TORI | 19 | RAIPUR |
| S8 | SORI | 19 | PARIS |
+-----+--------+--------+----------+
e))
For each shipment get full shipment details, including total shipment
weights.
mysql> select h.*, p.Weight_kg, (p.Weight_kg*h.Quantity) Total_Weight from shipment h, parts p where
p.PNo=h.PNo;
+-----+-----+-----+----------+-----------+--------------+
+-----+-----+-----+----------+-----------+--------------+
| S1 | P1 | J1 | 100 | 19 | 1900 |
| S1 | P1 | J2 | 500 | 19 | 9500 |
| S5 | P1 | J2 | 100 | 19 | 1900 |
| S1 | P2 | J4 | 360 | 23 | 8280 |
| S5 | P2 | J3 | 100 | 23 | 2300 |
| S5 | P2 | J5 | 200 | 23 | 4600 |
| S5 | P2 | J6 | 200 | 23 | 4600 |
| S9 | P2 | J2 | 200 | 23 | 4600 |
| S2 | P3 | J3 | 400 | 12 | 4800 |
| S4 | P3 | J1 | 100 | 12 | 1200 |
| S4 | P3 | J2 | 100 | 12 | 1200 |
| S8 | P3 | J2 | 57 | 12 | 684 |
| S2 | P4 | J1 | 750 | 22 | 16500 |
| S3 | P4 | J8 | 900 | 22 | 19800 |
| S5 | P4 | J3 | 200 | 22 | 4400 |
| S6 | P4 | J2 | 1500 | 22 | 33000 |
| S6 | P5 | J4 | 300 | 34 | 10200 |
| S3 | P6 | J8 | 2500 | 50 | 125000 |
| S6 | P6 | J8 | 50 | 50 | 2500 |
| S7 | P6 | J5 | 400 | 50 | 20000 |
| S6 | P7 | J7 | 300 | 30 | 9000 |
| S7 | P7 | J7 | 200 | 30 | 6000 |
| S4 | P8 | J2 | 500 | 40 | 20000 |
+-----+-----+-----+----------+-----------+--------------+
f))
Get all the shipments where the quantity is in the range 300 to 750
inclusive
+-----+-----+-----+----------+
+-----+-----+-----+----------+
| S1 | P1 | J2 | 500 |
| S1 | P2 | J4 | 360 |
| S2 | P3 | J3 | 400 |
| S2 | P4 | J1 | 750 |
| S4 | P8 | J2 | 500 |
| S6 | P5 | J4 | 300 |
| S6 | P7 | J7 | 300 |
| S7 | P6 | J5 | 400 |
+-----+-----+-----+----------+
g))
Get part nos. for parts that either weigh more than 16 pounds or are
supplied by
suppliers S2, or both.
mysql> (select distinct(P.Pno) from parts as P, shipment as Sh, suppliers as S where P.weight_kg>16 and
P.Pno=Sh.PNo and S.Sno=Sh.Sno) union (select distinct(P.Pno) from parts as P, shipment as Sh, suppliers
as S where S.Sno="S2" and P.Pno=Sh.Pno and S.Sno=Sh.Sno);
+-----+
| Pno |
+-----+
| P1 |
| P2 |
| P4 |
| P5 |
| P6 |
| P7 |
| P8 |
| P3 |
+-----+
h)
Get the names of cities that store more than five red parts.
mysql> select PCity, count(PNo) Number from parts group by PCity having count(PNo)>5;
+-------+--------+
| PCity | Number |
+-------+--------+
| PARIS | 6|
+-------+--------+
i)
Get full details of parts supplied by a supplier in London.
mysql> select P.* from Parts as P, Suppliers as S, Shipment as Sh where S.scity="London" and
P.Pno=Sh.Pno and S.Sno=Sh.Sno;
+-----+-------------+--------+-----------+--------+
+-----+-------------+--------+-----------+--------+
| P3 | SWITCH | RED | 12 | PARIS |
+-----+-------------+--------+-----------+--------+
j)
Get part numbers for part supplied by a supplier in London to a
project in London.
mysql> select P.Pno from Parts as P, Suppliers as S, project as pj, Shipment as Sh where S.Scity="London"
and Jcity="London" and P.Pno=Sh.Pno and S.Sno=Sh.Sno and pj.Jno=Sh.Jno;
+-----+
| Pno |
+-----+
| P4 |
+-----+
k)
Get the total number of project supplied by a supplier (say, S1)
mysql> select SNo, count(distinct JNo)Number_of_projects from shipment where Sno='S1';
+------+--------------------+
| SNo | Number_of_projects |
+------+--------------------+
| S1 | 3|
+------+--------------------+
l)
Get the total quantity of a part (say, P1) supplied by a supplier (say,
S1)
mysql> select SNo, PNo, sum(Quantity)Total_Quantity from shipment where SNo='S6' and PNo='P7';
+------+------+----------------+
+------+------+----------------+
| S6 | P7 | 300 |
+------+------+----------------+