Sei sulla pagina 1di 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 |

50 | | 8 | 117 | 100 | | 9 | 117 | 100 |
50 | | 8 | 117 | 100 | | 9 | 117 | 100 |
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

join moviecast natural join movies where year>2015

(select a.aid

from actor a natural

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

+--------+---------------------+---------+---------+

|

|

| 4 | operating system

| 5 | python programming | tmg

| 6 | java basics

| 7 | mechanic elements

| pname

| pubyear |

|

|

2007 |

2007 |

2013 |

|

2 | learn c++

3 | dbms

| pearson |

| nandi

| classis |

| tmg

| tmg

|

2017 |

2013 |

2013 |

| 8 | construction engg

| 9 | construction design | sunstar |

+--------+---------------------+---------+---------+

8 rows in set (0.00 sec)

| tmg

|

2013 |

2016 |

mysql> CREATE TABLE bookpartition PARTITION BY RANGE (pubyear) (

VALUES LESS THAN (2000), p2 VALUES LESS THAN (2010),

PARTITION p4 VALUES LESS THAN (2018) ) as select * from book; Query OK, 8 rows affected (0.25 sec)

Records: 8 Duplicates: 0 Warnings: 0

PARTITION p0

PARTITION

PARTITION p1 VALUES LESS THAN (2003), PARTITION p3 VALUES LESS THAN (2015),

mysql> SELECT PARTITION_NAME, TABLE_ROWS

INFORMATION_SCHEMA.PARTITIONS

+----------------+------------+

| PARTITION_NAME | TABLE_ROWS |

+----------------+------------+

FROM

WHERE TABLE_NAME = 'bookpartition';

| p0

|

0 |

| p1

|

0 |

| p2

|

2 |

| p3

|

4 |

| p4

|

2 |

+----------------+------------+

5 rows in set (0.00 sec)

mysql>