Library Program For Dbms
Library Program For Dbms
branchid int,
noofcopies int,
primary key(bookid,branchid),
foreign key(bookid) references book(bookid)on delete cascade,
foreign key(branchid) references libbranch(brachid));
select mname,mid,year
from director d, movies m
where d.did=m.did and dname='hitchcock';
select mname,mid,year
from movies
where did=(select did
from director
where dname='hitchcock');
Lab3:query2
select mname,m.mid
from moviecast mc,movies m
where m.mid=mc.mid and
aid in(select aid
from moviecast
group by aid
having count(*)>=2)
group by mid
having count(*)>=1;
Lab3:query3
select distinct aid,aname from actor natural join moviecast natural
join movies where aid in (select a.aid from actor a natural
join moviecast natural join movies where year>2015 and a.aid in
(select a.aid from actor a natural join moviecast natural join
movies where year<2000));
Lab3:query4
select mname,m.mid,max(revrate)
from movies m,rating r
where m.mid=r.mid
group by r.mid
having count(*)>0
order by mname;
Lab3:query5
update rating
set revrate=5
where mid in(
select m.mid
from movies m,director d
where d.did=m.did and dname='steven spielberg');
LAB01:QUERY01
select
b.bookid,title,b.pname,pubyear,authorname,lb.brachid,branc
hname,noofcopies
from book b,bookauthors ba, bookcopies bc,libbranch lb
where b.bookid=ba.bookid and
b.bookid=bc.bookid and
bc.branchid=lb.brachid;
LAB01:QUERY02
select bl.cardno,bname,baddr
from borrower b,blending1 bl
where b.cardno=bl.cardno and
dateout between '2017-01-01' and '2017-06-30'
group by bl.cardno
having count(*)>3;
LAB01:QUERY05
create view vbook as
select bc.bookid,title,sum(noofcopies)
from book b, bookcopies bc
where b.bookid=bc.bookid
group by bc.bookid;
LAB01:QUERY04
mysql> select * from book;
+--------+---------------------+---------+---------+
| bookid | title | pname | pubyear |
+--------+---------------------+---------+---------+
| 2 | learn c++ | pearson | 2007 |
| 3 | dbms | nandi | 2007 |
| 4 | operating system | classis | 2013 |
| 5 | python programming | tmg | 2017 |
| 6 | java basics | tmg | 2013 |
| 7 | mechanic elements | tmg | 2013 |
| 8 | construction engg | tmg | 2013 |
| 9 | construction design | sunstar | 2016 |
+--------+---------------------+---------+---------+
8 rows in set (0.00 sec)
mysql>