Library Database
Library Database
varchar(30),
constraint pkyPublisher primary key(Publisher_name));
(1)
(2)
insert into Book values(101,'Programming in C','PHI',2000);
insert into Book values(102,'Programming in C#','MHI',2002);
insert into Book values(103,'Computer Netwokrs','Dreamtech',2006);
insert into Book values(104,'Unix Shell Programming','PHI',2000);
insert into Book values(105,'Compiler Design','PHI',2010);
insert into Book values(106,'Database Management Systems','PHI',2008);
(3)
insert into Book_Authors values(101,'Balaguruswamy');
insert into Book_Authors values(102,'Andearson');
insert into Book_Authors values(103,'Ferouzan');
insert into Book_Authors values(104,'Sumitabha Das');
insert into Book_Authors values(105,'Kumar');
insert into Book_Authors values(106,'Tanenbaum');
(4)
insert into Library_programme values(1,'Technical','Jayanagar');
insert into Library_programme values(2,'Technical','Kuvempunagar');
insert into Library_programme values(3,'Advanced
Technology','Rajarajeshwarinagar');
insert into Library_programme values(4,'Technical','Vijaynagar');
insert into Library_programme values(5,'Advanced Technology','Vijaynagar');
(5)
insert into Book_Copies values(101,1,100);
insert into Book_Copies values(102,1,150);
insert into Book_Copies values(101,2,200);
insert into Book_Copies values(103,3,400);
insert into Book_Copies values(105,4,140);
insert into Book_Copies values(104,5,150);
(6)
insert into Book_Lending values(101,1,11,'2017-01-22','2017-02-07');
insert into Book_Lending values(102,1,22,'2017-01-22','2017-04-07');
insert into Book_Lending values(103,3,33,'2017-02-22','2017-04-07');
insert into Book_Lending values(104,5,44,'2017-01-22','2017-06-07');
insert into Book_Lending values(105,4,55,'2017-03-22','2017-05-07');
insert into Book_Lending values(101,2,66,'2017-04-22','2017-05-07');
insert into Book_Lending values(103,3,11,'2017-06-20','2017-07-07');
insert into Book_Lending values(104,5,11,'2017-03-12','2017-05-07');
insert into Book_Lending values(105,4,11,'2017-05-10','2017-05-07');
QUERIES
2. Get the particulars of borrowers who have borrowed more than 3 books, but
from Jan 2017 to Jun 2017.
3. Delete a book in BOOK table. Update the contents of other tables to reflect this
data manipulation operation.
4. Partition the BOOK table based on year of publication. Demonstrate its working
with a simple query.
5. Create a view of all books and its number of copies that are currently available
in the Library.
1)select B.Book_id,Title,Publisher_name,Author_name,No_of_copies
from Book B,Book_Authors A,Book_Copies C,Library_programme L
where B.Book_id=A.Book_id and
B.Book_id=C.Book_id and
C.programme_id=L.programme_id;
+---------+------------------------+----------------+---------------+--------------
+
| Book_id | Title | Publisher_name | Author_name | No_of_copies
|
+---------+------------------------+----------------+---------------+--------------
+
| 101 | Programming in C | PHI | Balaguruswamy | 100
|
| 101 | Programming in C | PHI | Balaguruswamy | 200
|
| 102 | Programming in C# | MHI | Andearson | 150
|
| 103 | Computer Netwokrs | Dreamtech | Ferouzan | 400
|
| 104 | Unix Shell Programming | PHI | Sumitabha Das | 150
|
| 105 | Compiler Design | PHI | Kumar | 140
|
+---------+------------------------+----------------+---------------+--------------
+
2)select Card_no,count(*)
from Book_Lending
where Date_Out between '2017-01-01' and '2017-06-30'
Group by Card_no
Having count(*) > 3;
+---------+----------+
| Card_no | count(*) |
+---------+----------+
| 11 | 4 |
+---------+----------+
+---------+------------------------+--------------+--------------+
| Book_id | Title | No_of_copies | programme_id |
+---------+------------------------+--------------+--------------+
| 101 | Programming in C | 100 | 1 |
| 102 | Programming in C# | 150 | 1 |
| 101 | Programming in C | 200 | 2 |
| 103 | Computer Netwokrs | 400 | 3 |
| 105 | Compiler Design | 140 | 4 |
| 104 | Unix Shell Programming | 150 | 5 |
+---------+------------------------+--------------+--------------+
+---------+-------+---------+-------+
| book_id | title | pname | pyear |
+---------+-------+---------+-------+
| 2 | cn | pearson | 1998 |
| 2 | dbms | pearson | 2000 |
| 2 | cn | pearson | 2009 |
| 3 | se | navathe | 2005 |
+---------+-------+---------+-------+
4 rows in set (0.00 sec)
use information_schema;
select * from partitions where table_name="b2";
+---------------+--------------+------------+----------------+-------------------
+----------------------------+-------------------------------+------------------
+---------------------+----------------------+-------------------------
+-----------------------+------------+----------------+-------------
+-----------------+--------------+-----------+---------------------
+---------------------+------------+----------+-------------------+-----------
+-----------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | PARTITION_NAME | SUBPARTITION_NAME |
PARTITION_ORDINAL_POSITION | SUBPARTITION_ORDINAL_POSITION | PARTITION_METHOD |
SUBPARTITION_METHOD | PARTITION_EXPRESSION | SUBPARTITION_EXPRESSION |
PARTITION_DESCRIPTION | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH
| INDEX_LENGTH | DATA_FREE | CREATE_TIME | UPDATE_TIME | CHECK_TIME
| CHECKSUM | PARTITION_COMMENT | NODEGROUP | TABLESPACE_NAME |
+---------------+--------------+------------+----------------+-------------------
+----------------------------+-------------------------------+------------------
+---------------------+----------------------+-------------------------
+-----------------------+------------+----------------+-------------
+-----------------+--------------+-----------+---------------------
+---------------------+------------+----------+-------------------+-----------
+-----------------+
| def | library | b2 | p0 | NULL |
1 | NULL | RANGE | NULL |
`pyear` | NULL | 2000 | 1
| 16384 | 16384 | 0 | 0 | 0 | 2020-
10-29 12:58:30 | 2020-10-29 12:58:45 | NULL | NULL | |
default | NULL |
| def | library | b2 | p1 | NULL |
2 | NULL | RANGE | NULL |
`pyear` | NULL | 2005 | 1
| 16384 | 16384 | 0 | 0 | 0 | 2020-
10-29 12:58:30 | 2020-10-29 12:58:45 | NULL | NULL | |
default | NULL |
| def | library | b2 | p2 | NULL |
3 | NULL | RANGE | NULL |
`pyear` | NULL | 2010 | 2
| 8192 | 16384 | 0 | 0 | 0 | 2020-
10-29 12:58:30 | 2020-10-29 12:58:49 | NULL | NULL | |
default | NULL |
+---------------+--------------+------------+----------------+-------------------
+----------------------------+-------------------------------+------------------
+---------------------+----------------------+-------------------------
+-----------------------+------------+----------------+-------------
+-----------------+--------------+-----------+---------------------
+---------------------+------------+----------+-------------------+-----------
+-----------------+
3 rows in set (0.11 sec)