0% found this document useful (0 votes)
81 views

Library Program For Dbms

The document shows the creation of two MySQL tables: bookcopies to store information about the number of copies of books at different library branches, and blending to track which patrons have checked out which books from which branches. It also includes some sample data inserted into these tables and describes the structure and fields of the blending table.

Uploaded by

Mujahid khaiser
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Library Program For Dbms

The document shows the creation of two MySQL tables: bookcopies to store information about the number of copies of books at different library branches, and blending to track which patrons have checked out which books from which branches. It also includes some sample data inserted into these tables and describes the structure and fields of the blending table.

Uploaded by

Mujahid khaiser
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

create table bookcopies(bookid int,

branchid int,
noofcopies int,
primary key(bookid,branchid),
foreign key(bookid) references book(bookid)on delete cascade,
foreign key(branchid) references libbranch(brachid));

mysql> select * from bookcopies;


+--------+----------+------------+
| bookid | branchid | noofcopies |
+--------+----------+------------+
| 1 | 111 | 20 |
| 1 | 112 | 50 |
| 2 | 112 | 50 |
| 2 | 119 | 50 |
| 3 | 119 | 50 |
| 4 | 119 | 10 |
| 6 | 113 | 50 |
| 7 | 115 | 50 |
| 8 | 117 | 100 |
| 9 | 117 | 100 |

mysql> create table blending(bookid int,


branchid int,
cardno int,
dateout date,
duedate date,
primary key(bookid,branchid,cardno),
foreign key (bookid) references book(bookid) on delete cascade,
foreign key(branchid) references libbranch(brachid));

mysql> desc blending;


+----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| bookid | int(11) | NO | PRI | 0 | |
| branchid | int(11) | NO | PRI | 0 | |
| cardno | int(11) | NO | PRI | 0 | |
| dateout | date | YES | | NULL | |
Lab3:query1
select mname,mid,year
from director natural join movies
where dname='hitchcock';

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;

select * from vbook;

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> CREATE TABLE bookpartition PARTITION BY RANGE (pubyear) ( PARTITION p0


VALUES LESS THAN (2000), PARTITION p1 VALUES LESS THAN (2003), PARTITION
p2 VALUES LESS THAN (2010), PARTITION p3 VALUES LESS THAN (2015),
PARTITION p4 VALUES LESS THAN (2018) ) as select * from book;
Query OK, 8 rows affected (0.25 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> SELECT PARTITION_NAME, TABLE_ROWS FROM


INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 'bookpartition';
+----------------+------------+
| PARTITION_NAME | TABLE_ROWS |
+----------------+------------+
| p0 | 0|
| p1 | 0|
| p2 | 2|
| p3 | 4|
| p4 | 2|
+----------------+------------+
5 rows in set (0.00 sec)

mysql>

You might also like