Dbms Lab-1
Dbms Lab-1
Week -2
Consider the Employee database given below. The primary keys are underlined.
Assume relevant data types for attributes.
EMPLOYEE (Fname, Lname, SSN, Addrs, Sex, Salary, SuperSSN, Dno)
DEPARTMENT (Dname, Dnumber, MgrSSN, MgrStartDate)
PROJECT(Pno, Pname, Dnum)
WORKS_ON (ESSN, Pno, Hours)
Week-3
Consider the insurance database given below. The primary keys are made
bold and the data types are specified.
PERSON( driver_id:string , name:string , address:string )
CAR( regno:string , model:string , year:int )
ACCIDENT( report_number:int , accd_date:date , location:string )
OWNS( driver_id:string , regno:string )
PARTICIPATED( driver_id:string , regno:string , report_number:int ,
damage_amount:int)
1)Create the above tables by properly specifying the primary keys and
foreign keys.
2)Enter at least five tuples for each relation.
3)Demonstrate how you
a.Update the damage amount for the car with specific regno in the
accident with report number 12 to 25000.
b.Add a new accident to the database.
4)Find the total number of people who owned cars that were involved in
accidents in the year 2008.
5)Find the number of accidents in which cars belonging to a specific
model were involved.
2.
3a.
3b.
4.
week-4
4.
OR
week 5
Consider the following database of student enrollment in courses and books
adopted for that course.
STUDENT( regno:string , name:string , major:string , bdate:date )
COURSE( courseno:int , cname:string , dept:string )
ENROLL( regno:string , courseno:int , sem:int , marks:int )
BOOK_ADOPTION( courseno:int , sem:int , book_isbn:int )
TEXT( book_isbn:int , book_title:string , publisher:string , author:string )
1)Create the above tables by properly specifying the primary keys and foreign
keys.
2)Enter atleast five tuples for each relation.
3)Demonstrate how you add a new text book to the database and make this book
to be adopted by some department.
4)Produce a list of text books ( includes courseno , book_isbn , book_title ) in
the alphabetical order for courses offered by the 'CS' department that use more
than two books.
5)List any department that has all its books published by a specific
publisher.SQL> create table student(regno varchar(10),name varchar(10),major
varchar(10),bdate date,primary key(regno));
2.
5.
SQL> select distinct c.dept from course c where not exists ((select b.book_isbn
from book_adoption b,course c1 where c1.courseno=b.courseno and
c1.dept=c.dept) minus (select book_isbn from text where publisher='BPB')) and
exists (select b.book_isbn from book_adoption b,course c1 where
c1.courseno=b.courseno and c1.dept=c.dept);
Week 6
2.
3.
4.
5.
2.
3.
4.
5.
SQL> delete from account where accno in (select a.accno from account
a,branch b where a.branch_name=b.branch_name and
b.branch_city='Bangalore');
WEEK 8
Consider the Cricket database given below. The primary keys are underlined. Assume relevant data
types for attributes.
Create the above tables in SQL. Specify primary and foreign keys properly. Enter at least 5 tuples in
each table with relevant data. Solve the following queries.
i. Display the sorted list of ground names where Australia has played as team1
ii. Find the match information of all matches in which Dhoni did batting.
iii. Find the names of players who did batting in match 2689
create table PLAYER (
Pid int,
Lname varchar(10),
Fname varchar(10),
Country varchar(10),
);
MatchID int,
Team1 varchar(10),
Team2 varchar(10),
Ground varchar(10),
primary key(MatchID)
);
MatchID int,
Pid int,
Nruns int,
);
MatchID int,
Pid int,
Novers int,
Maidens varchar(10),
);
//insert values
//Display the sorted list of ground names where Australia has played as team1.
SELECT Ground
FROM MATCHING
//Find the match information of all matches in which Dhoni did batting.
SELECT *
FROM (PLAYER natural join MATCHING) natural join BATTING WHERE Fname='Dhoni';
SELECT Fname,Lname
FROM (PLAYER natural join MATCHING) natural join BATTING WHERE MatchID=2686;
Create 10 collections with data relevant to the following questions. Write and execute MongoDB
queries:
i. List all the movies acted by John and Elly in the year 2012. ii. List only the name and type of
the movie where Ram has acted sorted by movie names
db.createCollection("movie")
{ "ok" : 1 }
db.movie.insert([{act_n:"ram",act_id:13,act_bdate:"2/3/1997",dir_n:"williams",dir_id:101,dir_bdat
e:"12/9/1987",film:"battleship",year:2015,type:"thriller"}])
db.movie.insert([{act_n:"john",act_id:11,act_bdate:"1/2/1998",dir_n:"ram",dir_id:100,dir_bdate:"2/
3/1997",film:"john wick",year:2012,type:"killer"}])
db.movie.insert([{act_n:"elly",act_id:12,act_bdate:"4/12/1998",dir_n:"ram",dir_id:100,dir_bdate:"2
/3/1997",film:"aquaman",year:2012,type:"action"}])
db.movie.insert([{act_n:"ram",act_id:13,act_bdate:"2/3/1997",dir_n:"thomas",dir_id:103,dir_bdate:
"12/3/1999",film:"xxx",year:2018,type:"action"}])
db.movie.insert([{act_n:"john",act_id:11,act_bdate:"1/2/1998",dir_n:"ram",dir_id:100,dir_bdate:"2/
3/1997",film:"mr.bean",year:2018,type:"comedy"}])
//List all the movies acted by John and Elly in the year 2012. db.movie.find({$and : [{act_n:{$in :
["john","elly"]}},{year:2012}]},{film:1}).pretty()
//ii. List only the name and type of the movie where Ram has acted sorted by movie names.
db.movie.find({act_n:"ram"},{film:1,type:1}).sort({film:1}).pretty()
Week 9
Consider the Aircraft database given below. The primary keys are underlined. Assume relevant data
types for attributes.
Create the above tables in SQL. Specify primary and foreign keys properly. Enter at least 5 tuples in
each table with relevant data. Solve the following queries.
aid varchar(9)
primary key, aname
varchar(10), crange
int
);
Create table
employees( eid
varchar(9) primary
key, ename
varchar(10), salary
int
);
);
SELECT aid
FROM aircraft
//Find the name of pilots who can operate flights with a range greater than 3000 miles but are not
certified on any Boeing aircraft.
select distinct(ename) from employees E,certified C, aircraft A where A.crange > 3000 and C.aid
NOT in(select aid from aircraft A where A.aname='Boeing') and E.eid = C.eid
Week 10
Consider the Supply-Parts database given below. The primary keys are underlined. Assume relevant
data types for attributes.
SUPPLIER (Sid, Sname, Address)
PART (PID, Pname, Color)
SHIPMENT (Sid, PID, Cost)
Create the above tables in SQL. Specify primary and foreign keys properly. Enter at least 5 tuples in
each table with relevant data. Solve the following queries.
);
);
);
Sid int,
//For every supplier print the name of the supplier and the total number of parts that he/she
supplies.
UPDATE PART
SET Color='Yellow'
WHERE PID IN (SELECT C.PID FROM SUPPLIER S, SHIPMENT C WHERE C.Sid=S.Sid and C.Sid=3);