DBMS LAB Programs For Mca
DBMS LAB Programs For Mca
Student (snum: integer, sname: string, major: string, level: string, age: 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 faculty members who teach in every room in which some class is
taught.
iv. Find the names of faculty members for whom the combined enrollment of the courses
that they teach is less than five.
1|P ag e
2019-20 19MCAL38 1NH18MCA39
SNUM CNAME
111 .net
222 Cobol
333 C
444 Java
555 Java
111 C
222 C
444 C
555 C
1.Find the names of all Juniors (level = JR) who are enrolled in a class taught by Prof.
Harshith
select distinct s1.sname from student s1, enrolled e, class c, faculty f where c.fid=f.fid and
c.cname=e.cname and s1.snum=e.snum and s1.slevel='jr' and f.fname='harshith';
SNAME
anil
varun
barath
sunil
2 Find the names of all classes that either meet in room R128 or have five or more Students
enrolled.
select distinct cname from class c where room='r128' or c.cname in(select e.cname from enrolled e
group by e.cname having count(*)>=5);
NAME
cobol
java
c
.net
3 Find the names of faculty members who teach in every room in which some class is taught.
select f.fname from faculty f where fid in (select fid from class group by fid having count(distinct
room)=(select count(distinct room) from class));
FNAME
harshith
3|P ag e
2019-20 19MCAL38 1NH18MCA39
4 Find the names of faculty members for whom the combined enrollment of the courses that
they teach is less than five.
select f.fname from faculty f where fid in(select distinct(fid)from class c, enrolled e where
c.cname=e.cname group by fid having count(fid)<5);
FNAME
snk
rc
sps
va
4|P ag e
2019-20 19MCAL38 1NH18MCA39
Flights (no: integer, from: string, to: string, distance: integer, Departs: time, arrives: time,
price: real)
Note that the Employees relation describes pilots and other kinds of employees as well; Every
pilot is certified for some aircraft, and only pilots are certified to fly.
i. Find the names of aircraft such that all pilots certified to operate them have salaries
more than Rs.80, 000.
ii. Find the names of pilots whose salary is less than the price of the cheapest route from
Bengaluru to Frankfurt.
iii. Find the names of pilots certified for some Boeing aircraft.
iv. Find the aids of all aircraft that can be used on routes from Bengaluru to New Delhi.
5|P ag e
2019-20 19MCAL38 1NH18MCA39
EID AID
1 500
2 501
3 504
5 502
3 503
3 501
3 504
6|P ag e
2019-20 19MCAL38 1NH18MCA39
1 Find the names of aircraft such that all pilots certified to operate them have salaries more
than Rs.80, 000
select aname from aircraft where aid in(select c.aid from certified c,employ e where c.eid=e.eid and
e.salary>80000);
ANAME
boeing
spicejet
2 Find the names of pilots whose salary is less than the price of the cheapest route from
Bengaluru to Frankfurt
select distinct e.ename from employ e, certified c where e.eid=c.eid and salary<(select min(price)
from flights where from1 like 'bangalore' and to1 like 'frankfurt');
ENAM
E
albert
john
priya
smith
select distinct(ename) from employ e, certified c,aircraft a where c.eid=e.eid and a.aid=c.aid and
aname= 'boeing';
ENAME
john
priya
4 Find the aids of all aircraft that can be used on routes from Bengaluru to New Delhi.
select aid from aircraft a where crusingrange>(select max(distance) from flights where
from1='bangalore' and to1='newdelhi');
AID
501
503
504
7|P ag e
2019-20 19MCAL38 1NH18MCA39
Consider the following database of student enrollment in courses & books adopted for each course.
(i) Create the above tables by properly specifying the primary keys and the foreign keys.
(ii) Enter at least five tuples for each relation.
(iii) Demonstrate how you add a new text book to the database and make this book be
adopted by some department.
(iv) Produce a list of text books (include Course #, Book-ISBN, Book-title) in the
alphabetical order for courses offered by the ‘CS’ department that use more than two
books
(v) List any department that has all its adopted books published by a specific publisher.
(vi) Generate suitable reports.
(i) Create the above tables by properly specifying the primary keys and the foreign keys.
Table created.
Table created.
Table created.
Table created.
8|P ag e
2019-20 19MCAL38 1NH18MCA39
Table created.
9|P ag e
2019-20 19MCAL38 1NH18MCA39
iii) Demonstrate how you add a new text book to the database and make this book be adopted
by some department.
1 row created.
1 row created.
10 | P a g e
2019-20 19MCAL38 1NH18MCA39
(iv) Produce a list of text books (include Course #, Book-ISBN, Book-title) in the alphabetical
order for courses offered by the ‘CS’ department that use more than two books
(v) List any department that has all its adopted books published by a specific publisher.
DEPT
Ec
manag
More than 10 rows available. Increase rows selector to view more rows.
i. Create the above tables by properly specifying the primary keys and the foreign keys.
ii. Enter at least five tuples for each relation.
iii. 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.
iv. Find the author of the book which has maximum sales.
v. Demonstrate how you increase the price of books published by a specific publisher by
10%.
vi. Generate suitable reports.
i) Create the above tables by properly specifying the primary keys and the foreign
keys.
12 | P a g e
2019-20 19MCAL38 1NH18MCA39
CATEGORY_ID DESCRIP
11 magazine
12 computer
13 novel
14 poems
15 pgming
iii) 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.
select * from author where author_id in(select author_id from catalog1 where (year>2000) and
(catalog1.price > (select avg(price)from catalog1)) group by author_id having count(*)>=2);
14 | P a g e
2019-20 19MCAL38 1NH18MCA39
iv) Find the author of the book which has maximum sales.
select name from author where author_id in (select author_id from catalog1 where book_id in(select
book_id from order_det group by book_id having sum(qty)in (select max(sum(qty)) from order_det
group by book_id)));
NAME
anil
v) Demonstrate how you increase the price of books published by a specific publisher by 10%.
2 row(s) updated
15 | P a g e
2019-20 19MCAL38 1NH18MCA39
16 | P a g e
2019-20 19MCAL38 1NH18MCA39
DEPOSITOR(customer-name:string, accno:int)
BORROWER(customer-name:string, loan-number:int)
i. Create the above tables by properly specifying the primary keys and the foreign keys
ii. Enter at least five tuples for each relation
iii.Find all the customers who have at least two accounts at the Main branch.
iv. Find all the customers who have an account at all the branches located in a specific city.
v. Demonstrate how you delete all account tuples at every branch located in a specific
city.
vi. Generate suitable reports.
i) Create the above tables by properly specifying the primary keys and the foreign
keys
branch(bname),amount number(6));
17 | P a g e
2019-20 19MCAL38 1NH18MCA39
18 | P a g e
2019-20 19MCAL38 1NH18MCA39
CUST_NAME ACCNO
abhinav 23856
anil 19901
anil 19956
anil 25115
manish 19956
CUST_NAME LOAN_NO
anil 36969
anil 21001
ankit 78911
amit 56091
amit 51234
19 | P a g e
2019-20 19MCAL38 1NH18MCA39
iii) Find all the customers who have at least two accounts at the Main branch.
select cust_name from depositor d, account a where a.accno=d.accno and a.bname='peenya' group by
d.cust_name having count(*)>=2;
CUST_NAME
anil
iv) Find all the customers who have an account at all the branches located in a specific
city
select distinct cust_name from depositor d,account a,branch b where d.accno=a.accno and
b.bname=a.bname and b.bcity='bangalore' group by cust_name having count(distinct
a.bname)>=(select count(distinct bname)from branch where bcity='bangalore');
CUST_NAME
anil
v) Demonstrate how you delete all account tuples at every branch located in a specific city.
delete from depositor where accno in(select accno from account where bname in(select bname
from branch where bcity='bangalore'));
2 row(s) deleted.
delete from account where bname in(select bname from branch where bcity='bangalore');
2 row(s) deleted.
20 | P a g e