18CSL58 LAB Programs
18CSL58 LAB Programs
CREDITS 02
Design, develop, and implement the specified queries for the following problems using
environment.
Create Schema and insert at least 5 records for each table. Add appropriate
database constraints.
Use Java, C#, PHP, Python, or any other similar front-end tool. All applications
Give these details only for 8th semester A, B, and C section student
5. Consider the schema for Company Database:
EMPLOYEE (SSN, Name, Address, Sex, Salary, SuperSSN, DNo)
DEPARTMENT (DNo, DName, MgrSSN, MgrStartDate)
DLOCATION (DNo, DLoc) PROJECT (PNo, PName, PLocation,
DNo) WORKS_ON( SSN, PNo, Hours)
Write SQL queries to
1. Make a list of all project numbers for projects that involve an employee whose last
name is either as a worker or as a manager of the department that controls the
project.
2. Show the resulting salaries if is given a
10 percent raise.
3. Find the sum of the salaries of all employees of the 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).
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.
Part B: Mini project
For any problem selected
Make sure that the application should have five or more
tables Indicative areas include; health care
Course outcomes: The students should be able
to: Create, Update and query on the
database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
Conduction of Practical Examination:
Experiment distribution
1. For laboratories having only one part: Students are allowed to pick one experiment from
the lot with equal opportunity.
2. For laboratories having PART A and PART B: Students are allowed to pick one
experiment from PART A and one experiment from PART B, with equal opportunity.
3. Change of experiment is allowed only once and marks allotted for procedure to be made
zero of the changed part only.
4. Marks Distribution (Coursed to change in accordance with university regulations)
5. For laboratories having only one part Procedure + Execution + Viva-Voce: 15+70+15 =100 Marks
6. For laboratories having PART A and PART B
i. Part A Procedure + Execution + Viva = 6 + 28 + 6 = 40 Marks
ii. Part B Procedure + Execution + Viva = 9 + 42 + 9 = 60 Marks
DBMS Laboratory with mini Project 18CSL58
LAB EXPERIMENTS
Program Objectives:
This course will enable students to
Foundation knowledge in database concepts, technology and practice to groom
students into well-informed database application developers.
Strong practice in SQL programming through a variety of database problems.
Develop database applications using front-end tools and back-end DBMS.
Table Creation
Table Descriptions
DESC BOOK
;
DESC BOOK_AUTHORS;
DESC PUBLISHER;
DESC BOOK_COPIES
DESC CARD;
DESC LIBRARY_PROGRAMME
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;
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.
CREATE VIEW VW_BOOKS AS SELECT B.BOOK_ID, B.TITLE, C.NO_OF_COPIES
FROM BOOK B, BOOK_COPIES C, LIBRARY_PROGRAMME L WHERE
B.BOOK_ID=C.BOOK_ID AND C.PROGRAMME_ID=L.PROGRAMME_ID;
Program Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
Program Objectives:
Solution:
Entity-Relationship Diagram
This course will enable students to
Foundation knowledge in database concepts, technology and practice to groom
students into well-informed database application developers.
Strong practice in SQL programming through a variety of database problems.
Develop database applications using front-end tools and back-end DBMS.
Table Creation
DESC SALESMAN;
DESC CUSTOMER;
DESC ORDERS;
Insertion of Value
INSERT INTO SALESMAN VALUES(101,'RICHARD','LOS ANGELES','18%');
INSERT INTO SALESMAN VALUES(103,'GEORGE','NEWYORK','32%');
INSERT INTO SALESMAN VALUES(110,'CHARLES','BANGALORE','54%');
INSERT INTO SALESMAN VALUES(122,'ROWLING','PHILADELPHIA','46%');
INSERT INTO SALESMAN VALUES(126,'KURT','CHICAGO','52%');
INSERT INTO SALESMAN VALUES(132,'EDWIN','PHOENIX','41%');
SELECT GRADE,COUNT(DISTINCT
2. Find the name and FROM
CUSTOMER_ID) numbers of all salesmen
CUSTOMER who BY
GROUP had more than one customer.
SELECT
GRADESALESMAN_ID,NAME
FROM
HAVINGSALESMAN A
GRADE >(SELECT AVG(GRADE) FROM CUSTOMER
WHERE
WHERE1CITY='BANGALORE');
<(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.)
4. Create a view that finds the salesman who has the customer with the highest order of
a day.
CREATE VIEW VW_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);
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 Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
Program Objectives:
Solution:
Entity-Relationship Diagram
This course will enable students to
Foundation knowledge in database concepts, technology and practice to groom students
into well-informed database application developers.
Strong practice in SQL programming through a variety of database problems.
Develop database applications using front-end tools and back-end DBMS.
Table Creation
CREATE TABLE ACTOR (
ACT_ID INT (5) PRIMARY KEY,
ACT_NAME VARCHAR (20),
ACT_GENDER CHAR (1));
Table Descriptions
DESC ACTOR;
DESC DIRECTOR;
DESC MOVIES;
DESC MOVIES_CAST;
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 Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
Give these details only for 8th semester A, B, and C section students.
Program Objectives:
Solution:
Entity - This
Relationship Diagram
course will enable students to
Foundation knowledge in database concepts, technology and practice to groom
students into well-informed database application developers.
Strong practice in SQL programming through a variety of database problems.
Develop database applications using front-end tools and back-end DBMS.
Schema Diagram
Table Creation
CREATE TABLE STUDENT (
USN VARCHAR (10) PRIMARY KEY,
SNAME VARCHAR (25),
ADDRESS VARCHAR (25),
PHONE BIGINT (10),
GENDER CHAR (1));
Table Descriptions
DESC STUDENT;
DESC SEMSEC;
DESC CLASS;
DESC IAMARKS;
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.
CREATE VIEW VW_STUDENT_TEST AS SELECT TEST1,SUBCODE FROM
IAMARKS WHERE USN= 4AD13CS091';
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 Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
project.
2. Show the resulting salaries if every employee
percent raise.
3.
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).
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.
Solution:
Program Objectives:
Entity-Relationship Diagram
This course will enable students to
Foundation knowledge in database concepts, technology and practice to groom
students into well-informed database application developers.
Strong practice in SQL programming through a variety of database problems.
Develop database applications using front-end tools and back-end DBMS.
Schema Diagram
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);
Dept. of ISE, GNDEC, Bidar Page 45
DBMS Laboratory with mini Project 18CSL58
CREATE TABLE DLOCATION (
DLOC VARCHAR (20),
DNO VARCHAR (20),
PRIMARY KEY (DNO, DLOC),
FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNO));
Table Descriptions
DESC EMPLOYEE;
DESC DEPARTMENT;
DESC PROJECT;
DESC PROJECT;
DESC WORKS_ON;
Note: update entries of employee table to fill missing fields SUPERSSN and DNO
UPDATE EMPLOYEE SET SUPE
UPDATE EMPLOYEE
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
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;