DBMS Lab Mannual
DBMS Lab Mannual
Introduction To DataBase
Management System Lab Manual
For 4th Semester
Course Code: 22ADL47
By
Prof. Revati Sugoor
List of Experiments
LIBRARY DATABASE
1. Demonstrating creation of tables, applying the view concepts on the tables.
1. Retrieve details of all books in the library – id, title, name of publisher, authors, number of
copies in each Programme, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2022 to
Jun 2022.
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. Create a view of all books and its number of copies that are currently
available in the library.
ORDER DATABASE:
2. Discuss the various concepts on constraints and update operations.
3. Demonstrate the concepts of JOIN operations.Consider the schema for Movie Database:
ACTOR (Act_id, Act_Name, Act_Gender)
DIRECTOR (Dir_id, Dir_Name, Dir_Phone)
MOVIES (Mov_id, Mov_Title, Mov_Year, Mov_Lang, Dir_id)
MOVIE_CAST (Act_id, Mov_id, Role)
RATING (Mov_id, Rev_Stars)
COLLEGE DATABASE
5. Demonstrate the core concepts on table like nested and correlated nested queries and
also EXISTS and NOT-EXISTS keywords.
1 Retrieve details of all books in the library – id, title, name of publisher, authors, number of copies in
each Programme, etc.
2 Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2022 to Jun 2022.
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. Create a view of all books and its number of copies that are currently available in the library.
SCHEMA DIAGRAM
Table Creation
AUTHOR_NAME BOOK_ID
NAVATHE 1
NAVATHE 2
ULLMAN 3
CHARLES 4
GALVIN 5
CARDNO
101
102
103
104
105
3 CD PEARSON ULLMAN 7 14
5 OS PEARSON GALVIN 3 10
2. Get the particulars of borrowers who have borrowed more than 3 books, but from
Jan 2017 to Jun 2017.
SELECT CARD_NO FROM BOOK_LENDING WHERE DATE_OUT
BETWEEN '2017-01-01'AND '2017-07-01' GROUP BY CARD_NO HAVING COUNT(*)>3;
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.
CREATE VIEW VW_PUBLICATION AS SELECT PUB_YEAR FROM BOOK;
6. Create a view of all books and its number of copies that are currently available in
the Library.
ORDER DATABASE:
2 Discuss the various concepts on constraints and update operations.
Table Creation
DESC SALESMAN;
DESC CUSTOMER;
DESC ORDERS;
Insertion of Value
2. Find the name and numbers of all salesmen who had more than one customer.
SELECT SALESMAN_ID,NAME
FROM SALESMAN A
WHERE 1 <(SELECT COUNT(*) FROM CUSTOMER
WHERE SALESMAN_ID=A.SALESMAN_ID)
OR
SELECT S.SALESMAN_ID,NAME, FROM
CUSTOMER C,SALESMAN S WHERE
S.SALESMAN_ID=C.SALESMAN_ID GROUP BY
C.SALESMAN_ID HAVING COUNT(*)>1
3. their cities
(Use UNION operation.)
5. Demonstrate the DELETE operation by removing salesman with id 1000. All his
orders must also be deleted.
Use ON DELETE CASCADE at the end of foreign key definitions while creating child table
orders and then execute the following:
PROGRAM-3
Solution:
Entity-Relationship Diagram
SCHEMA DIAGRAM
Table Creation
CREATE TABLE ACTOR (
ACT_ID INT (5) PRIMARY KEY,
ACT_NAME VARCHAR (20),
ACT_GENDER CHAR (1));
9563400156);
INSERT INTO DIRECTOR VALUES(102,'ALAN TAYLOR',9971960035);
25);
75);
INSERT INTO DIRECTOR VALUES (105,'HITCHCOCK',7766138911);
INSERT INTO DIRECTOR VALUES (106,'STEVEN SPIELBERG',9966138934);
MOV_ID REV_STARS
501 4
502 2
503 5
504 4
505 3
506 2
507 2
508 4
OR
SELECT MOV_TITLE FROM MOVIES M, DIRECTOR D WHERE M.DIR_ID=D.DIR_ID
AND DIR_NAME='HITCHCOCK';
2. Find the movie names where one or more actors acted in two or more movies.
SELECT MOV_TITLE FROM MOVIES M,MOVIES_CAST MV
WHERE M.MOV_ID=MV.MOV_ID AND ACT_ID IN(SELECT ACT_ID FROM
MOVIES_CAST GROUP BY ACT_ID HAVING COUNT(ACT_ID)>1) GROUP BY
MOV_TITLE HAVING COUNT(*)>1;
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use
JOIN operation).
SELECT ACT_NAME, MOV_TITLE, MOV_YEAR FROM ACTOR A JOIN
MOVIE_CAST C ON A.ACT_ID=C.ACT_ID INNER JOIN MOVIES M
ON C.MOV_ID=M.MOV_ID WHERE M.MOV_YEAR NOT BETWEEN 2000 AND 2015;
5. 5
UPDATE RATING SET REV_STARS=5 WHERE MOV_ID IN(SELECT MOV_ID FROM
MOVIES WHERE DIR_ID IN(SELECT DIR_ID FROM DIRECTOR
WHERE DIR_NAME='STEVEN SPIELBERG'));
OR
UPDATE RATING R, MOVIES M, DIRECTOR D SET REV_STARS=5 WHERE
R.MOV_ID=M.MOV_ID AND M.DIR_ID=D.DIR_ID AND DIR_NAME='STEVEN
SPIELBERG';
PROGRAM-4
COLLEGE DATABASE
SCHEMA DIAGRAM
DEPARTMENT OF ARARTIFICIAL INTELLIGENCE & DATA SCIENCE Page 27
INTRODUCTION TO DATABASE MANGEMENT SYSTEM LAB
INTRODUCTION TO DBMS LAB 22ADL47
Table Creation
CREATE TABLE STUDENT (
USN VARCHAR (10) PRIMARY KEY,
SNAME VARCHAR (25),
ADDRESS VARCHAR (25),
PHONE BIGINT (10),
GENDER CHAR (1));
CREATE TABLECLASS
(USN VARCHAR (10),
SSID VARCHAR (5),
PRIMARY KEY (USN, SSID),
FOREIGN KEY (USN) REFERENCES STUDENT (USN),
FOREIGN KEY (SSID) REFERENCES SEMSEC (SSID));
SELECT * FROM
SELECT S.*, SS.SEM, SS.SEC FROM STUDENT S, SEMSEC SS, CLASS C WHERE
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
WHERE S.USN = C.USN AND SS.SSID = C.SSID
GROUP BY SS.SEM, SS.SEC, S.GENDER ORDER BY SEM;
3.
Subjects.
4. Calculate the FinalIA (average of best two test marks) and update the corresponding
table for all students.
UPDATE IAMARKS
SET FINALIA=GREATEST(TEST1+TEST2,TEST2+TEST3,TEST1+TEST3)/2;
Note: Before execution above SQL statement, IAMARKS table contents are:
UPDATE IAMARKS
SET FINALIA=GREATEST(TEST1+TEST2,TEST2+TEST3,TEST1+TEST3)/2;
Give these details only for 8th semester A, B, and C section students.
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;
PROGRAM 5
COMPANY DATABASE
5 Demonstrate the core concepts on table like nested and correlated nested queries and also EXISTS
and NOT-EXISTS keywords.
Table Creation
NOTE: Once DEPARTMENT and EMPLOYEE tables are created we must alter department
table to add foreign constraint MGRSSN using sql command
ALTER TABLE DEPARTMENT ADD FOREIGN KEY(MGRSSN) REFERENCES
EMPLOYEE(SSN);
Queries:
1. Make a list of all project numbers for projects that involve an employee whose last name
UNION
(SELECT DISTINCT P1.PNO FROM PROJECT P1, WORKS_ON W, EMPLOYEE E1 WHERE
2.
percent raise.
SELECT E.FNAME, E.LNAME, 1.1*E.SALARY AS INCR_SAL FROM EMPLOYEE E,
WORKS_ON W, PROJECT P WHERE E.SSN=W.SSN AND W.PNO=P.PNO AND
3
maximum salary, the minimum salary, and the average salary in this department
SELECT SUM (E.SALARY), MAX (E.SALARY), MIN (E.SALARY), AVG (E.SALARY)
FROM EMPLOYEE E, DEPARTMENT D WHERE E.DNO=D.DNO AND
4. Retrieve the name of each employee who works on all the projects Controlled
by department number 5 (use NOT EXISTS operator).
SELECT E.FNAME,E.LNAME FROM EMPLOYEE E WHERE NOT EXISTS
(SELECT PNO FROM PROJECT P WHERE DNO=5 AND PNO NOT IN
(SELECT PNO FROM WORKS_ON W WHERE E.SSN=SSN));
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;
EIOIQWOU