Lab Programs
Lab Programs
[ISO Certified 9000:2008, Affiliated to VTU, Belgaum, Approved by AICTE, New Delhi]
181/1, Hoodi Village, Sonnenahalli, K.R.Puram, Bangalore – 560 048
CERTIFICATE
1.
2.
DBMS LABORATORY WITH MINI PROJECT
(Effective from the academic year 2018 -2019)
SEMESTER – V
Course Code 18CSL58 CIE Marks 40
Number of Contact Hours/Week 0:2:2 SEE Marks 60
Total Number of Lab Contact Hours 36 Exam Hours 03
Credits – 2
Course Learning Objectives: This course (18CSL58) 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.
Descriptions (if any):
PART-A: SQL Programming (Max. Exam Mks. 50)
• Design, develop, and implement the specified queries for the following problems using
Oracle, MySQL, MS SQL Server, or any other DBMS under LINUX/Windows
environment.
• Create Schema and insert at least 5 records for each table. Add appropriate database
constraints.
PART-B: Mini Project (Max. Exam Mks. 30)
• Use Java, C#, PHP, Python, or any other similar front-end tool. All applications must
be demonstrated on desktop/laptop as a stand-alone or web based application (Mobile
apps on Android/IOS are not permitted.)
Installation procedure of the required software must be demonstrated, carried out in
groups and documented in the journal.
Programs List:
PART A
1. Consider the following schema for a Library Database:
BOOK(Book_id, Title, Publisher_Name, Pub_Year)
BOOK_AUTHORS(Book_id, Author_Name)
PUBLISHER(Name, Address, Phone)
BOOK_COPIES(Book_id, Programme_id, No-of_Copies)
BOOK_LENDING(Book_id, Programme_id, Card_No, Date_Out, Due_Date)
LIBRARY_PROGRAMME(Programme_id, Programme_Name, Address)
Write SQL queries to
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 2017 to Jun 2017.
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.
2. Consider the following schema for Order Database:
SALESMAN(Salesman_id, Name, City, Commission)
CUSTOMER(Customer_id, Cust_Name, City, Grade, Salesman_id)
ORDERS(Ord_No, Purchase_Amt, Ord_Date, Customer_id, Salesman_id)
Write SQL queries to
1. Count the customers with grades above Bangalore’s average.
2. Find the name and numbers of all salesman who had more than one customer.
3. List all the salesman and indicate those who have and don’t have customers
in their cities (Use UNION operation.)
4. Create a view that finds the salesman who has the customer with the highest
order of a day.
5. Demonstrate the DELETE operation by removing salesman with id 1000. All
his orders must also be deleted.
3. 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)
Write SQL queries to
1. List the titles of all movies directed by ‘Hitchcock’.
2. Find the movie names where one or more actors acted in two or more movies.
3. List all actors who acted in a movie before 2000 and also in a movie after
2015 (use JOIN operation).
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.
5. Update rating of all movies directed by ‘Steven Spielberg’ to 5.
4. Consider the schema for College Database:
STUDENT(USN, SName, Address, Phone, Gender)
SEMSEC(SSID, Sem, Sec)
CLASS(USN, SSID)
COURSE(Subcode, Title, Sem, Credits)
IAMARKS(USN, Subcode, SSID, Test1, Test2, Test3, FinalIA)
Write SQL queries to
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 Courses.
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.
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 ‘Scott’, either as a worker or as a manager of the department that
controls the project.
2. Show the resulting salaries if every employee working on the ‘IoT’ project is
given a 10 percent raise.
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
controlledby 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
Laboratory Outcomes: The student 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.
Conduct of Practical Examination:
• Experiment distribution o For laboratories having only one part: Students are allowed
to pick one experiment from the lot with equal opportunity.
o 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.
• Change of experiment is allowed only once and marks allotted for procedure to be
made zero of the changed part only. • Marks Distribution (Courseed to change in
accoradance with university regulations)
k) For laboratories having only one part – Procedure + Execution + Viva-Voce:
15+70+15 =
100 Marks
l) 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 LAB PROGRAMS (15CSL58)
Lab Program 1
AIM: Create table, querying the Library database and perform all the operations using sql.
ER DIAGRAM
SCHEMA DIAGRAM
TABLE CREATION:
QUERY1: Retrieve details of all books in the library – id, title, name of publisher,
authors, number of copies in each branch, etc.
mysql> SELECT
C.BRANCH_ID,B.BOOK_ID,B.TITLE,B.PUBLISHER_NAME,A.AUTHOR_NAME,C.N0_OF_
COPIES FROM BOOK B,BOOK_AUTHORS A,BOOK_COPIES C WHERE
B.BOOK_ID=A.BOOK_ID AND B.BOOK_ID=C.BOOK_ID ORDER BY C.BRANCH_ID;
+-----------+---------+-------+----------------+-------------+--------------+
| BRANCH_ID | BOOK_ID | TITLE | PUBLISHER_NAME | AUTHOR_NAME |
N0_OF_COPIES |
+-----------+---------+-------+----------------+-------------+--------------+
| 11 | 1 | CG | MCGRAW | GALVIN | 100 |
| 12 | 2 | CN | MCGRAW | FOROUZAN | 200 |
| 13 | 3 | CPP | NAVATHE | SUMITA | 300 |
+-----------+---------+-------+----------------+-------------+--------------+
3 rows in set (0.00 sec)
QUERY2: Get the particulars of borrowers who have borrowed more than 3 books, but
from Jan 2017 to Jun 2017.
QUERY3: Delete a book in BOOK table. Update the contents of other tables to reflect
this data manipulation operation.
QUERY4: Partition the BOOK table based on year of publication. Demonstrate its
working with a simple query.
QUERY5: Create a view of all books and its number of copies that are currently
available in the Library.
CONCLUSION: Tables are created and the values have been inserted accordingly and all the
mentioned queries have been executed.
Lab Program 2
AIM: Create table, querying the Order database and perform all the operations using sql.
ER DIAGRAM:
SCHEMA DIAGRAM
TABLE CREATION
create table salesman(salesman_id int(5) not null primary key, name varchar(10), city varchar(10),
commission int(8));
Query OK, 0 rows affected (0.09 sec)
create table customer(customer_id int(5) not null primary key, cust_name varchar(10), city
varchar(10), grade int(8),salesman_id int (5), foreign key(salesman_id) references
salesman(salesman_id) on delete cascade);
Query OK, 0 rows affected (0.07 sec)
mysql> select count(*) from customer where grade>(select avg(grade)from customer where
city='bangalore');
+----------+
| count(*) |
+----------+
| 2|
+----------+
1 row in set (0.00 sec)
Query2: Find the name and numbers of all salesman who had more than one customer
Query3: List all the salesman and indicate those who have and don’t have customers in
their cities (Use UNION operation.)
mysql> (select distinct s.salesman_id,s.name,'same city' from customer c,salesman s where
c.salesman_id=s.salesman_id and c.city=s.city) union (select distinct
s.salesman_id,s.name,'different city' from customer c,salesman s where
c.salesman_id=s.salesman_id and c.city != s.city) union (select distinct s.salesman_id,s.name,'no
customer' from salesman s where salesman_id not in (select salesman_id from customer));
+-------------+------+-------------+
| salesman_id | name | same city |
+-------------+------+-------------+
| 1 | abc | same city |
| 3 | xyz | same city |
| 4 | pqr | same city |
| 2 | abc | no customer |
+-------------+------+-------------+
4 rows in set (0.00 sec)
Query4: Create a view that finds the salesman who has the customer with the highest
order of a day.
Query5: Demonstrate the DELETE operation by removing salesman with id 1000. All
his orders must also be deleted.
CONCLUSION: Tables are created and the values have been inserted accordingly and all the
mentioned queries have been executed.
Lab Program 3
AIM: Create table, querying the Movie database and perform all the operations using sql.
ER DIAGRAM:
SCHEMA DIAGRAM:
TABLE CREATION
QUERY 2:
QUERY 3: Find the movie names where one or more actors acted in two or more movies.
QUERY 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.
mysql> update rating set rev_stars= 5 where mov_id in(select mov_id from movies m ,director d
where d.director_id=m.director_id and director_name='rakesh');
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0
CONCLUSION: Tables are created and the values have been inserted accordingly and all the
mentioned queries have been executed.
Lab Program 4
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.
AIM: Create table, querying the College database and perform all the operations using sql.
ER DIAGRAM
SCHEMA DIAGRAM
TABLE CREATION:
mysql> create table student(usn varchar(10) primary key,name varchar(20),address
varchar(20),phone double,gender varchar(5));
Query OK, 0 rows affected (0.25 sec)
mysql> create table class(usn varchar(10) primary key,ssid int(5),foreign key(usn) references
student(usn) on delete cascade,foreign key(ssid) references semsec(ssid));
Query OK, 0 rows affected (0.17 sec)
mysql> select s.* from student s,semsec ss,class c where s.usn=c.usn and ss.ssid=c.ssid and
ss.sem=4 and ss.sec='C';
+------------+----------+-----------+------------+--------+
| usn | name | address | phone | gender |
+------------+----------+-----------+------------+--------+
| 1GD16CS002 | rohit | pune | 9090786766 | M |
| 1GD16CS001 | akanksha | bangalore | 9090786756 | F |
+------------+----------+-----------+------------+--------+
2 rows in set (0.02 sec)
QUERY 2: Compute the total number of male and female students in each semester and each
section.
mysql> select sem,sec,gender ,count(gender) from student natural join class natural join semsec
group by sem,sec,gender;
+------+------+--------+---------------+
| sem | sec | gender | count(gender) |
+------+------+--------+---------------+
| 1|B |M | 1|
| 4|C |F | 1|
| 4|C |M | 1|
| 7|A |F | 1|
+------+------+--------+---------------+
4 rows in set (0.03 sec)
mysql> select sem,sec,gender ,count(gender) from student natural join class natural join semsec
group by sem,sec,gender;
+------+------+--------+---------------+
| sem | sec | gender | count(gender) |
+------+------+--------+---------------+
| 1|B |M | 1|
| 4|C |F | 1|
| 4|C |M | 2|
| 7|A |F | 1|
+------+------+--------+---------------+ 4 rows in set (0.03 sec)
QUERY 3: Create a view of Test1 marks of student USN ‘1GD16CS001’ in all subjects
QUERY4: Calculate the FinalIA (average of best two test marks) and update the
corresponding table for all students.
(P.S : put any row with semester 8 and maximum marks should be 20)
CONCLUSION: Tables are created and the values have been inserted accordingly and all the
mentioned queries have been executed.
Lab Program 5
AIM: Create table, querying the Company database and perform all the operations using sql.
ER DIAGRAM
SCHEMA DIAGRAM:
TABLE CREATION:
mysql> create table department(dno int(5) primary key, dname varchar(10), mgrssn varchar(10),
mgrstartdate date);
Query OK, 0 rows affected (0.07 sec)
mysql> create table employee(ssn varchar(10) primary key, name varchar(10), address varchar(15),
sex varchar(4), salary double, superssn varchar(10), dno int(5),foreign key(superssn) references
employee(ssn),foreign key(dno) references department(dno));
Query OK, 0 rows affected (0.09 sec)
mysql> create table dlocation(dno int(5), dloc varchar(15), primary key(dno,dloc), foreign key(dno)
references department(dno));
Query OK, 0 rows affected (0.08 sec)
mysql> create table project(pno int(5) primary key, pname varchar(10), ploc varchar(10), dno
int(5), foreign key(dno) references department(dno) on delete cascade);
Query OK, 0 rows affected (0.13 sec)
mysql> create table works_on(ssn varchar(10), pno int(5), hours int, primary key(ssn,pno), foreign
key(ssn) references employee(ssn) on delete cascade, foreign key(pno) references project(pno) on
delete cascade);
Query OK, 0 rows affected (0.12 sec)
Query1: . 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 the project.
mysql> (select pno from project p,department d,employee e where p.dno=d.dno and e.ssn=d.mgrssn
and e.name='scott')
union
(select pno from employee e,works_on w where e.ssn=w.ssn and e.name='scott');
+-----+
| pno |
+-----+
| 301 |
+-----+
1 row in set (0.00 sec)
Query2: Show the resulting salaries if every employee working on the ‘IoT’ project is
given a 10 percent raise.
mysql> select e.ssn,salary*1.1 from employee e, works_on w, project p where e.ssn=w.ssn and
w.pno=p.pno and pname='IOT';
+------+--------------------+
| ssn | salary*1.1 |
+------+--------------------+
| W101 | 27500.000000000004 |
| W102 | 16500 |
+------+--------------------+
2 rows in set (0.01 sec)
Query3: 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
mysql> select dname, max(salary), min(salary), avg(salary) from employee e, department d where
e.dno=d.dno and d.dname='account';
+---------+-------------+-------------+-------------+
| dname | max(salary) | min(salary) | avg(salary) |
+---------+-------------+-------------+-------------+
| account | 600000 | 15000 | 307500 |
+---------+-------------+-------------+-------------+
1 row in set (0.00 sec)
Query4: Retrieve the name of each employee who works on all the projects
controlledby department number 5 (use NOT EXISTS operator).
mysql> select e.name from employee e where not exists (select pno from project where dno=4 and
pno not in (select pno from works_on w where w.ssn=e.ssn));
+------+
| name |
+------+
| john |
+------+
1 row in set (0.00 sec)
Query5: 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.
mysql> select dno, count(ssn) from employee where salary> 600000 and dno in (select dno from
employee group by dno having count(ssn)>0);
+------+------------+
| dno | count(ssn) |
+------+------------+
| 4| 1|
+------+------------+
1 row in set (0.00 sec)
CONCLUSION: Tables are created and the values have been inserted accordingly and all the
mentioned queries have been executed.