DBMS Lab Mannual
DBMS Lab Mannual
Program 1
DESC DEPARTMENT;
----------------------------------
DESC EMPLOYEE;
----------------------------------
-- ADD FOREIGN KEY Constraint to DEPARTMENT table
----------------------------------
--Create Table DLOCATION with PRIMARY KEY as DNO and DLOC and FOREIGN KEY
DNO referring DEPARTMENT table
DESC DLOCATION;
----------------------------------
--Create Table PROJECT with PRIMARY KEY as PNO and FOREIGN KEY DNO referring
DEPARTMENT table
DESC PROJECT;
----------------------------------
--Create Table WORKS_ON with PRIMARY KEY as PNO and SSN and FOREIGN KEY SSN
and PNO referring EMPLOYEE and PROJECT table
DESC WORKS_ON;
----------------------------------
----------------------------------
----------------------------------
-------------------------------
--------------------------------
------------------------------
1. Select ename, address from Employee, department where dname=”ISE” and dno=dnumber;
2. Select E.ename , S.ename from employee E, employee S where E.superssn=S.ssn;
3. Select sum(salary) from Employee;
4. Select dno, count(ssn),AVG(salary) from employee group by dno;
C. Create table employee(ename varchar(15), ssn int, bdate int, sex varchar(10),address
varchar(20),salary int, Primary Key(ssn));
desc employee;
5. Select ename, address from Employee, department where dname=”ISE” and dno=dnumber;
6. Select E.ename , S.ename from employee E, employee S where E.superssn=S.ssn;
7. Select sum(salary) from Employee;
8. Select dno, count(ssn),AVG(salary) from employee group by dno;
Program 2
2. Consider the following relation schema:
SAILORS (Sid: integer, Sname: string, Rating: integer, Age: real)
BOATS (Bid: integer, Bname: string, Color: string)
RESERVES (sid: integer, Bid: integer, Day:date)
Create above tables by specifying primary key, foreign key and other suitable constraints. Insert
atleast 5 tuples to each created table. Design a database to the satisfy the above requirements and
answer following queries
i. Find all sailors with a rating above 7
ii. Find the names of sailors who have reserved boat number 103
iii. Find the names of sailors who have reserved a red boat
iv. Find the names of sailors who have reserved a red or a green boat
C. create table reserve(Sid int, Bid int, Day date, Primary Key(Sid,Bid),Foreign Key(Sid) references
sailor(Sid),Foreign Key(Bid) references boat(Bid));
desc reserve;
insert into reserve values(1,101,"2021-10-10");
insert into reserve values(2,102,"2021-11-10");
insert into reserve values(3,103,"2021-12-10");
insert into reserve values(4,104,"2021-10-15");
insert into reserve values(5,105,"2021-11-14");
select *from Reserve ;
Program 3
3. Consider the following relation schema:
STUDENT (Snum: integer, Sname: string, Major: string, Level: string, Age: integer)
CLASS (Cname: string, Meets at: string, Room: string, Fid: integer) ENROLLED (Snum:
integer, Cname: string)
FACULTY (Fid: integer, Fname: string, Deptid: integer)
The meaning of these relations is straightforward; for example, enrolled has one record per
student-class pair such that the student is enrolled in the class. Level is a two character code with
4 different values (example: Junior: JR etc) Write the following queries in SQL. No duplicates
should be printed in any of the answers.
i. Find the names of all Juniors (level = JR) who are enrolled in a class taught by Prof.
Harshith
ii. Find the names of all classes that either meet in room R128 or have five or more Students
enrolled.
iii. Find the names of all students who are enrolled in two classes that meet at the same time.
iv. Find the names of faculty members who teach in every room in which some class is taught.
create database Student4MC19IS040;
use Student4MC19IS040;
A. create table student(Snum int, Sname varchar(15),Major varchar(15),Level varchar(15),Age real,
Primary Key(Snum));
desc student;
insert into student values(1,"Rajat","IS","Third",21);
insert into student values(2,"Rajeeva","CS","Third",21);
insert into student values(3,"Suhas","Mech","Third",21);
insert into student values(4,"Reeshu","Civil","Third",21);
insert into student values(5,"Likhith","EC","Fourth",21);
insert into student values(6,"Hemashree","EC","Second",21);
insert into student values(7,"Sanvitha","EC","First",21);
insert into student values(8,"Anushree","EC","Second",21);
select *from student ;
Program 4
4. Consider the relation schema for book dealer database:
AUTHOR (Author-id:int, Name:string, City:string, Country:string)
PUBLISHER (Publisher-id:int, Name:string, City:string, Country:string)
CATALOG (Book-id:int, Title:string, Author-id:int, Publisher-id:int, Category-id:int, Year:int,
Price:int)
CATEGORY (Category-id:int, Description:string)
ORDER-DETAILS (Order-no:int, Book-id:int, Quantity:int)
Create the above tables by properly specifying the primary keys and the foreign keys. Enter
atleast five tuples for each relation.
i. Give the details of the authors who have 2 or more books in the catalog and the price of the
books is greater than the average price of the books in the catalog and the year of
publication is after 2000.
ii. Find the author of the book which has maximum sales.
iii. Demonstrate how you increase the price of books published by a specific publisher by 10%
iv. List any department that has all its adopted books published by a specific publisher
create database Book040;
use Book040;
A. create table AUTHOR(Authorid int, Name varchar(15),City varchar(15),Country varchar(15),
Primary Key(Authorid));
desc AUTHOR;
insert into AUTHOR values(1,"Ram","Bangalore","India");
insert into AUTHOR values(2,"Shyam","San Fransisco","USA");
insert into AUTHOR values(3,"Bheem","Sydney","Australia");
insert into AUTHOR values(4,"Radhe","Colombo","Srilanka");
insert into AUTHOR values(5,"Alex","Pune","India");
select *from AUTHOR ;
1. select * from AUTHOR where Authorid in(select Authorid from CATALOG where Year>=2000
and Price>(Select avg (Price) from CATALOG) Group by Authorid having count(*)>=2) ;
2. Select distinct Name from AUTHOR a,ORDERDETAILS o,CATALOG c where
o.quantity=(select max(Quantity) from ORDERDETAILS) and o.Bookid=c.Bookid and
c.Authorid=a.Authorid;
3. update CATALOG set Price=Price*1.1 where Publisherid in(select Publisherid from
PUBLISHER p where p.Name="Hemashree");
Program 5
5. 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 Create the above tables by properly specifying the primary keys and the
foreign keys. Enter atleast five tuples for each relation.
i. List the titles of all movies directed by ‘Hitchcock’.
ii. Find the movie names where one or more actors acted in two or more movies.
iii. List all actors who acted in a movie before 2000 and also in a movie after 2015.
iv. Update rating of all movies directed by ‘Steven Spielberg’ to 5.
create database movie;
use movie;
A. create table actor(act_id int,act_name varchar(30),act_gender varchar(5), primary key (act_id));
insert into actor values(1,'darshan','male');
insert into actor values(2,'punith','male');
insert into actor values(3,'vijay','male');
insert into actor values(4,'vinod','male');
1. select mov_title from movies m ,director d where d.dir_name="sunil" and d.dir_id = m.dir_id;
2. select mov_title from movies m,moviecast mc where m.mov_id=mc.mov_id and act_id in (select
act_id from moviecast groupby act_id having count (act_id)>1);
3. select m.mov_title, a.act_id, m.mov_year from actor a, movies m, moviecast mc where
m.mov_year not between 2000 and 2015;
4. select mov_title,max(rev_stars) from movies m, rating r where m.mov_id = r.mov_id groupby
mov_title having count(rev_stars)>0 orderby m.mov_title;
Program 6
5. Consider the following database for a banking enterprise
BRANCH (branch-name: String, branch-city: String, assets: real)
ACCOUNTS (accno: int, branch-name: String, balance: real)
DEPOSITOR (customer-name: String, customer-street: String, customer-city: String)
LOAN (loan-number: int, branch-name: String, amount: real)
BORROWER (customer-name: String, loan-number: int)
Create the above tables by properly specifying the primary keys and the foreign keys. Enter
atleast five tuples for each relation.
i.Find all the customers who have at least two accounts at the Main branch.
ii.Find all the customers who have an account at all the branches located in a specific city.
iii.Demonstrate how you delete all account tuples at every branch located in a specific city.