DBMS Report
DBMS Report
1. Retrieve details of all books in the library – id, title, name of publisher, authors,
number of copies in each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from
Jan 2019 to Jun 2020
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulation operation.
4. Partition the BOOK table based on year of publication. Demonstrate its working
with a simple query.
5. Create a view of all books and its number of copies that are currently available in the
Library.
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
1. List all the student details studying in fourth semester ‘C’ section.
2. Compute the total number of male and female students in each semester and in
each section.
3. Create a view of Test1 marks of student USN ‘1BI15CS101’ in all subjects.
4. Calculate the FinalIA (average of best two test marks) and update the corresponding
table for all students.
5. Categorize students based on the following criterion: If FinalIA = 17 to 20 then CAT
= ‘Outstanding’ If FinalIA = 12 to 16 then CAT = ‘Average’ If FinalIA< 12 then
CAT = ‘Weak’ Give these details only for 8th semester A, B, and C section students.
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Solution:
Entity-Relationship Diagram
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Schema Diagram
BOOK
Table Creation
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
DUE_DATE DATE,
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 8
DATABASE MANAGEMENT SYSTEMS LABORATORY
Queries:
1. Retrieve details of all books in the library – id, title, name of publisher,
authors, number of copies in each branch,etc.
Dept of 9
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
2. Get the particulars of borrowers who have borrowed more than 3 books, but
from Jan 2017 to Jun2017
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
CARD_NO
101
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
3. Delete a book in BOOK table. Update the contents of other tables to reflect this
data manipulationoperation
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
1 row(s) deleted.
Output:
5 OS May-16 PEARSON
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
4. Partition the BOOK table based on year of publication. Demonstrate its working with
a simplequery.
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
PUB_YEAR
Jan-17
Jun-16
May-16
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
5. Create a view of all books and its number of copies that are currently available in the
Library.
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
Solution:
Entity-Relationship Diagram:
Dept of 1
DATABASE MANAGEMENT SYSTEMS LABORATORY
Schema Diagram
Table Creation
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
ORD_DATE DATE,
PRIMARY KEY (ORD_NO),
CUSTOMER_ID REFERENCES CUSTOMER1 (CUSTOMER_ID) ON DELETE
CASCADE, SALESMAN_ID REFERENCES SALESMAN (SALESMAN_ID) ON
DELETE CASCADE);
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
Queries:
SELECT GRADE,
COUNT (DISTINCT CUSTOMER_ID) AS "CUSTOMER GRADE FOR BANGALORE"
FROM CUSTOMER1 GROUP BY GRADE HAVING GRADE > (SELECT AVG(GRADE)
FROM CUSTOMER1 WHERE
CITY='BANGALORE');
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
OUTPUT:
300 1
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
2. Find the name and numbers of all salesmen who had more than onecustomer.
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
SALESMAN_ID NAME
1000 JOHN
2000 RAVI
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
3. List all salesmen and indicate those who have and don’t have customers in their
cities (Use UNIONoperation.)
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
4. Create a view that finds the salesman who has the customer with the highest order
of a day.
CREATE VIEW ELITSALESMAN AS SELECT B.ORD_DATE,
A. SALESMAN_ID,
A.NAME FROM SALESMAN A, ORDERS B WHERE A.
SALESMAN_ID = B. SALESMAN_ID
AND B.PURCHASE_AMT=(SELECT MAX
(PURCHASE_AMT) FROM ORDERS C
WHERE C.ORD_DATE = B.ORD_DATE);
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 2
DATABASE MANAGEMENT SYSTEMS LABORATORY
Use ON DELETE CASCADE at the end of foreign key definitions while creating child table
orders and then execute the following:
Use ON DELETE SET NULL at the end of foreign key definitions while creating child table
customers and then executes the following:
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Solution:
Entity-Relationship Diagram
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Table Creation :
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Queries:
SELECT MOV_TITLE
FROM MOVIES
FROM DIRECTOR
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
MOV_TITLE
AKASH
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
2. Find the movie names where one or more actors acted in two or moremovies.
SELECT MOV_TITLE
FROM MOVIES M, MOVIE_CAST MV
WHERE M.MOV_ID=MV.MOV_ID AND ACT_ID IN (SELECT ACT_ID
FROM MOVIE_CAST GROUP BY ACT_ID HAVING COUNT (ACT_ID)>1)
GROUP BY MOV_TITLE HAVING
COUNT (*)>1;
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
MOV_TITLE
BAHUBALI-1
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use
JOINoperation).
Dept of 3
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
4. Find the title of movies and number of stars for each movie that has at least
one rating and find the highest number of stars that movie received. Sort the
result by movie title.
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
MOV_TITLE MAX(REV_STARS)
AKASH 5
BAHUBALI-1 2
BAHUBALI-2 4
WAR HORSE 4
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
MOV_ID REV_STARS
1001 4
1002 2
1003 5
1004 5
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Addres
sem
Phone SSID sec
USN
gender
SNAME
student semsec
class
secures
title
Class_ma rks subcode
sem
Test1
IAmarks credits
subject
Test2
Scored_in
Test3
finalIA
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Schema Diagram :
Table Creation :
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 4
DATABASE MANAGEMENT SYSTEMS LABORATORY
('1RN14CS032','CSE7A');
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Queries:
1. List all the student details studying in fourth semester
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
2. Compute the total number of male and female students in each semester and in
each section.
SELECT SS.SEM, SS.SEC, S.GENDER, COUNT (S.GENDER) AS COUNT FROM
STUDENT S, SEMSEC SS, CLASS C
WHERES.USN = C.USNAND
SS.SSID =C.SSID
GROUP BY SS.SEM, SS.SEC, S.GENDER
ORDER BYSEM;
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
SEM S G COUNT
3 A M 1
3 B F 1
3 C M 1
4 A F 1
4 A M 1
4 B M 1
4 C M 1
7 A F 1
7 A M 2
8 A F 1
8 A M 1
8 B F 1
8 C F 1
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
TEST1 SUBCODE
15 10CS81
12 10CS82
19 10CS83
201 10CS84
15 10CS85
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
4. Calculate the FinalIA (average of best two test marks) and update the
corresponding table for allstudents.
CURSOR C_IAMARKS IS
SELECT GREATEST(TEST1,TEST2)
AS A, GREATEST(TEST1,TEST3)
AS B, GREATEST(TEST3,TEST2) ASC
FROM IAMARKS
WHERE FINALIA IS NULL
FOR UPDATE;
C_ANUMBER;
C_BNUMBER;
C_CNUMBER;
C_SMNUMBER;
C_AVNUMBER;
BEGIN
OPEN C_IAMARKS;
LOOP
FETCH C_IAMARKS INTO C_A, C_B, C_C;
EXIT WHEN C_IAMARKS%NOTFOUND;
--DBMS_OUTPUT.PUT_LINE(C_A || ' ' || C_B || ' ' || C_C); IF
(C_A != C_B) THEN
C_SM:=C_A+C_B; ELSE
C_SM:=C_A+C_C;
END IF;
C_AV:=C_SM/2;
--DBMS_OUTPUT.PUT_LINE('SUM = '||C_SM);
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
--DBMS_OUTPUT.PUT_LINE('AVERAGE = '||C_AV);
UPDATE IAMARKS SET FINALIA=C_AV WHERE CURRENT OF C_IAMARKS;
END LOOP;
CLOSE
C_IAMARKS;
END;
Dept of 5
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Below SQL code is to invoke the PL/SQL stored procedure from the command line:
BEGIN
AVGMARKS;E
ND;
Output:
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
SELECT S.USN,S.SNAME,S.ADDRESS,S.PHONE,S.GENDER,
(CASE
WHEN IA.FINALIA BETWEEN 17 AND 20 THEN'OUTSTANDING' WHEN
IA.FINALIA BETWEEN 12 AND 16 THEN 'AVERAGE' ELSE 'WEAK' END)
AS CAT
FROM STUDENT S, SEMSEC SS, IAMARKS IA, SUBJECT SUB
WHERE S.USN = IA.USN AND
SS.SSID = IA.SSID AND
SUB.SUBCODE = IA.SUBCODE AND
SUB.SEM = 8;
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
DLOCATION (DNo,DLoc)
1. Make a list of all project numbers for projects that involve an employee whose last name
is ‘Scott’, either as a worker or as a manager of the department that controls theproject.
2. Show the resulting salaries if every employee working on the ‘IoT’ project is given a
10 percentraise.
3. Find the sum of the salaries of all employees of the ‘Accounts’ department, as well as the
maximum salary, the minimum salary, and the average salary in this department
4. Retrieve the name of each employee who works on all the projects controlled by
department number 5 (use NOT EXISTS operator). For each department that has more
than five employees, retrieve the department number and the number of its employees who
are making more than Rs.6,00,000.
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Entity-Relationship Diagram :
Schema Diagram :
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Table Creation:
NOTE: Once DEPARTMENT and EMPLOYEE tables are created we must alter department
table to add foreign constraint MGRSSN using sql comman
NOTE: Once DEPARTMENT and EMPLOYEE tables are created we must alter department
table to add foreign constraint MGRSSN using sql command
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Note: update entries of employee table to fill missing fields SUPERSSN and DNO
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Queries:
1. Make a list of all project numbers for projects that involve an employee whose
last name is ‘Scott’, either as a worker or as a manager of the department that
controlsthe project.
WHERE E.DNO=D.DNO
AND D.MGRSSN=E.SSN
AND E.LNAME=‘SCOTT‘)
UNION
WHERE P1.PNO=W.PNO
AND E1.SSN=W.SSN
AND E1.LNAME=‘SCOTT‘);
Dept of 6
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
PNO
100
101
102
103
104
105
106
107
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
2. Show the resulting salaries if every employee working on the ‘IoT’ project is
given a10 percentraise.
E, WORKS_ON W,
P.PNAME='IOT';
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
3. Find the sum of the salaries of all employees of the ‘Accounts’ department, as well
as the maximum salary, the minimum salary, and the average salary in
thisdepartment
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
4. Retrieve the name of each employee who works on all the projects Controlled by
department number 5 (use NOT EXISTSoperator).
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
FNAME LNAME
JAMES SMITH
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
5. For each department that has more than five employees, retrieve the
department number and the number of its employees who are making more than
Rs. 6,00,000
SELECT D.DNO, COUNT (*)
FROM DEPARTMENT D, EMPLOYEE E
WHERE D.DNO=E.DNO
AND E.SALARY>600000
AND D.DNO IN (SELECT E1.DNO
FROM EMPLOYEE E1 GROUP
BY E1.DNO HAVING COUNT
(*)>5)
GROUP BY D.DNO;
Dept of 7
DATABASE MANAGEMENT SYSTEMS LABORATORY
Output:
DNO COUNT(*)
5 3
Dept of 7