You are on page 1of 9

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 16
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use databse 4mt21ai017


ERROR 1049 (42000): Unknown database 'databse'
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| 4mt21ai017_library |
| cs050 |
| information_schema |
| mysql |
| orders |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
9 rows in set (0.00 sec)

mysql> use 4mt21ai017_library;


Database changed
mysql> show tables;
+------------------------------+
| Tables_in_4mt21ai017_library |
+------------------------------+
| book |
| book_authors |
| book_copies |
| book_lending |
| card |
| library_programme |
| publisher |
+------------------------------+
7 rows in set (0.00 sec)

mysql> select * from book;


+---------+-------------------+--------------------+-------------+
| book_id | title | publisher_name | pub_year |
+---------+-------------------+--------------------+-------------+
| 101 | 2 States | Arihant publishers | 19 May 2017 |
| 102 | Godaan | Bandup books | 10 Jan 2017 |
| 103 | Safed | Geeko books | 5 Jun 2017 |
| 104 | Screwed by Murder | Penguin books | 6 Aug 2017 |
| 105 | Merry Christmas | Xpert books | 17 Dec 2022 |
+---------+-------------------+--------------------+-------------+
5 rows in set (0.00 sec)
mysql> select * book_authors;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'book_authors' at line 1
mysql> select *from book_authors
-> ;
+---------+-----------------+
| book_id | author_name |
+---------+-----------------+
| 101 | Chetan Bhagat |
| 102 | Premchand |
| 103 | Abhay verma |
| 104 | Saurabh Katyal |
| 105 | Sriram Raghavan |
+---------+-----------------+
5 rows in set (0.00 sec)

mysql> select *from book_copies;


Empty set (0.00 sec)

mysql> select * from book_copies;


Empty set (0.00 sec)

mysql> select * from library_programme;


+--------------+----------------+------------------+
| programme_id | programme_name | address |
+--------------+----------------+------------------+
| 1 | Rom-com | Mumbai |
| 2 | Folk-lore | Varanasi |
| 3 | Biography | Assam |
| 4 | Crome-thriller | Himachal Pradesh |
| 5 | Dark-comedy | Kerala |
+--------------+----------------+------------------+
5 rows in set (0.00 sec)

mysql> select * from book_copies;


Empty set (0.00 sec)

mysql> desc book_copies;


+--------------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| programme_id | int | NO | PRI | NULL | |
| no_of_copies | int | YES | | NULL | |
+--------------+------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into book_copies values(101,1,5260);


Query OK, 1 row affected (0.00 sec)

mysql> insert into book_copies values(102,2,4896);


Query OK, 1 row affected (0.00 sec)

mysql> insert into book_copies values(103,3,8965);


Query OK, 1 row affected (0.00 sec)

mysql> insert into book_copies values(104,4,6875);


Query OK, 1 row affected (0.00 sec)
mysql> insert into book_copies values(105,5,7896);
Query OK, 1 row affected (0.00 sec)

mysql> select * from book_copies;


+---------+--------------+--------------+
| book_id | programme_id | no_of_copies |
+---------+--------------+--------------+
| 101 | 1 | 5260 |
| 102 | 2 | 4896 |
| 103 | 3 | 8965 |
| 104 | 4 | 6875 |
| 105 | 5 | 7896 |
+---------+--------------+--------------+
5 rows in set (0.00 sec)

mysql> select * from book_lending;


Empty set (0.01 sec)

mysql> desc book_lending;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| programme_id | int | NO | PRI | NULL | |
| card_id | int | NO | PRI | NULL | |
| date_out | varchar(20) | YES | | NULL | |
| due_date | varchar(20) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> select * from card;


Empty set (0.01 sec)

mysql> select * from library_programme;


+--------------+----------------+------------------+
| programme_id | programme_name | address |
+--------------+----------------+------------------+
| 1 | Rom-com | Mumbai |
| 2 | Folk-lore | Varanasi |
| 3 | Biography | Assam |
| 4 | Crome-thriller | Himachal Pradesh |
| 5 | Dark-comedy | Kerala |
+--------------+----------------+------------------+
5 rows in set (0.00 sec)

mysql> select * from publisher;


+--------------------+--------------------------+------------+
| name | address | phone |
+--------------------+--------------------------+------------+
| Arihant publishers | Jai-colony Uttar-Pradesh | 8976589645 |
| Bandup books | Raniganj villa Udgaon | 7895469856 |
| Geeko books | Andhadhun complex,Bandra | 7760069856 |
| Penguin books | 18-Rani-penthouse Kasoli | 9876548698 |
| Xpert books | Freddy colony,ooty | 8795645689 |
+--------------------+--------------------------+------------+
5 rows in set (0.00 sec)

mysql> desc card;


+---------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------+------+-----+---------+-------+
| card_id | int | NO | PRI | NULL | |
+---------+------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> desc book_lending;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| programme_id | int | NO | PRI | NULL | |
| card_id | int | NO | PRI | NULL | |
| date_out | varchar(20) | YES | | NULL | |
| due_date | varchar(20) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> insert into card values(2001);


Query OK, 1 row affected (0.00 sec)

mysql> insert into card values(2002);


Query OK, 1 row affected (0.01 sec)

mysql> insert into card values(2003);


Query OK, 1 row affected (0.01 sec)

mysql> insert into card values(2004);


Query OK, 1 row affected (0.00 sec)

mysql> insert into card values(2005);


Query OK, 1 row affected (0.00 sec)

mysql> select * from card;


+---------+
| card_id |
+---------+
| 2001 |
| 2002 |
| 2003 |
| 2004 |
| 2005 |
+---------+
5 rows in set (0.00 sec)

mysql> select * from book_lending;


Empty set (0.00 sec)

mysql> insert into book_lending values(101,1,2001,14jan2017,20jan2017);


ERROR 1054 (42S22): Unknown column '14jan2017' in 'field list'
mysql> insert into book_lending values(101,1,2001,"14jan2017","20jan2017");
Query OK, 1 row affected (0.01 sec)

mysql> insert into book_lending values(102,2,2002,"10feb2023","20marc2023");


Query OK, 1 row affected (0.00 sec)

mysql> insert into book_lending values(103,3,2003,"2aug2021","20sep2021");


Query OK, 1 row affected (0.00 sec)
mysql> insert into book_lending values(104,4,2004,"20marc2017","2apr2017");
Query OK, 1 row affected (0.00 sec)

mysql> insert into book_lending values(105,5,2005,"20may2018","2june2018");


Query OK, 1 row affected (0.00 sec)

mysql> select * from book_lending;


+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2002 | 10feb2023 | 20marc2023 |
| 103 | 3 | 2003 | 2aug2021 | 20sep2021 |
| 104 | 4 | 2004 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2005 | 20may2018 | 2june2018 |
+---------+--------------+---------+------------+------------+
5 rows in set (0.00 sec)

mysql> select * from publisher;


+--------------------+--------------------------+------------+
| name | address | phone |
+--------------------+--------------------------+------------+
| Arihant publishers | Jai-colony Uttar-Pradesh | 8976589645 |
| Bandup books | Raniganj villa Udgaon | 7895469856 |
| Geeko books | Andhadhun complex,Bandra | 7760069856 |
| Penguin books | 18-Rani-penthouse Kasoli | 9876548698 |
| Xpert books | Freddy colony,ooty | 8795645689 |
+--------------------+--------------------------+------------+
5 rows in set (0.00 sec)

mysql> select * from book_id;


ERROR 1146 (42S02): Table '4mt21ai017_library.book_id' doesn't exist
mysql> select * from book;
+---------+-------------------+--------------------+-------------+
| book_id | title | publisher_name | pub_year |
+---------+-------------------+--------------------+-------------+
| 101 | 2 States | Arihant publishers | 19 May 2017 |
| 102 | Godaan | Bandup books | 10 Jan 2017 |
| 103 | Safed | Geeko books | 5 Jun 2017 |
| 104 | Screwed by Murder | Penguin books | 6 Aug 2017 |
| 105 | Merry Christmas | Xpert books | 17 Dec 2022 |
+---------+-------------------+--------------------+-------------+
5 rows in set (0.00 sec)

mysql> select * from book_authors;


+---------+-----------------+
| book_id | author_name |
+---------+-----------------+
| 101 | Chetan Bhagat |
| 102 | Premchand |
| 103 | Abhay verma |
| 104 | Saurabh Katyal |
| 105 | Sriram Raghavan |
+---------+-----------------+
5 rows in set (0.00 sec)

mysql> select * from book_lending;


+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2002 | 10feb2023 | 20marc2023 |
| 103 | 3 | 2003 | 2aug2021 | 20sep2021 |
| 104 | 4 | 2004 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2005 | 20may2018 | 2june2018 |
+---------+--------------+---------+------------+------------+
5 rows in set (0.00 sec)

mysql> select * from card;


+---------+
| card_id |
+---------+
| 2001 |
| 2002 |
| 2003 |
| 2004 |
| 2005 |
+---------+
5 rows in set (0.00 sec)

mysql> select * from library_programme;


+--------------+----------------+------------------+
| programme_id | programme_name | address |
+--------------+----------------+------------------+
| 1 | Rom-com | Mumbai |
| 2 | Folk-lore | Varanasi |
| 3 | Biography | Assam |
| 4 | Crome-thriller | Himachal Pradesh |
| 5 | Dark-comedy | Kerala |
+--------------+----------------+------------------+
5 rows in set (0.00 sec)

mysql> select * from publisher;


+--------------------+--------------------------+------------+
| name | address | phone |
+--------------------+--------------------------+------------+
| Arihant publishers | Jai-colony Uttar-Pradesh | 8976589645 |
| Bandup books | Raniganj villa Udgaon | 7895469856 |
| Geeko books | Andhadhun complex,Bandra | 7760069856 |
| Penguin books | 18-Rani-penthouse Kasoli | 9876548698 |
| Xpert books | Freddy colony,ooty | 8795645689 |
+--------------------+--------------------------+------------+
5 rows in set (0.00 sec)

mysql> select * from book_copies;


+---------+--------------+--------------+
| book_id | programme_id | no_of_copies |
+---------+--------------+--------------+
| 101 | 1 | 5260 |
| 102 | 2 | 4896 |
| 103 | 3 | 8965 |
| 104 | 4 | 6875 |
| 105 | 5 | 7896 |
+---------+--------------+--------------+
5 rows in set (0.00 sec)

mysql> show tables;


+------------------------------+
| Tables_in_4mt21ai017_library |
+------------------------------+
| book |
| book_authors |
| book_copies |
| book_lending |
| card |
| library_programme |
| publisher |
+------------------------------+
7 rows in set (0.01 sec)

mysql> desc book;


+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| title | varchar(20) | YES | | NULL | |
| publisher_name | varchar(25) | YES | MUL | NULL | |
| pub_year | varchar(20) | YES | | NULL | |
+----------------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> desc book_authors;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| book_id | int | YES | MUL | NULL | |
| author_name | varchar(25) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> select
a.book_id,a.title,a.publisher_name,b.author_name,d.no_of_copies,f.programme_id from
book a,book_authors b,book_copies d,library_programme f where a.book_id=b.book_id
and a.book_id=d.book_id and f.programme_id=d.programme_id;
+---------+-------------------+--------------------+-----------------
+--------------+--------------+
| book_id | title | publisher_name | author_name | no_of_copies
| programme_id |
+---------+-------------------+--------------------+-----------------
+--------------+--------------+
| 101 | 2 States | Arihant publishers | Chetan Bhagat | 5260
| 1 |
| 102 | Godaan | Bandup books | Premchand | 4896
| 2 |
| 103 | Safed | Geeko books | Abhay verma | 8965
| 3 |
| 104 | Screwed by Murder | Penguin books | Saurabh Katyal | 6875
| 4 |
| 105 | Merry Christmas | Xpert books | Sriram Raghavan | 7896
| 5 |
+---------+-------------------+--------------------+-----------------
+--------------+--------------+
5 rows in set (0.00 sec)

mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql>
mysql> delete from book where book_
-> ;
ERROR 1054 (42S22): Unknown column 'book_' in 'where clause'
mysql> delete from b
-> oo;
ERROR 1146 (42S02): Table '4mt21ai017_library.b' doesn't exist
mysql> delete from book where book_id=103;
Query OK, 1 row affected (0.01 sec)

mysql> select * from book_id;


ERROR 1146 (42S02): Table '4mt21ai017_library.book_id' doesn't exist
mysql> select * from book;
+---------+-------------------+--------------------+-------------+
| book_id | title | publisher_name | pub_year |
+---------+-------------------+--------------------+-------------+
| 101 | 2 States | Arihant publishers | 19 May 2017 |
| 102 | Godaan | Bandup books | 10 Jan 2017 |
| 104 | Screwed by Murder | Penguin books | 6 Aug 2017 |
| 105 | Merry Christmas | Xpert books | 17 Dec 2022 |
+---------+-------------------+--------------------+-------------+
4 rows in set (0.00 sec)

mysql> create lp[;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'lp[' at
line 1
mysql> create vw-pub_year as select pub_year from book;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'vw-
pub_year as select pub_year from book' at line 1
mysql> create view vw-pub_year as select pub_year from book;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '-
pub_year as select pub_year from book' at line 1
mysql> create view pub_year as select pub_year from book;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from pub_year;


+-------------+
| pub_year |
+-------------+
| 19 May 2017 |
| 10 Jan 2017 |
| 6 Aug 2017 |
| 17 Dec 2022 |
+-------------+
4 rows in set (0.03 sec)
mysql> select card_id
-> from book_lending
-> where due_date between '1jan2017' and '1jun2017'
-> group by card_id
-> having count(*)>0;
Empty set (0.00 sec)

mysql> select * from book_lending;


+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2002 | 10feb2023 | 20marc2023 |
| 104 | 4 | 2004 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2005 | 20may2018 | 2june2018 |
+---------+--------------+---------+------------+------------+
4 rows in set (0.00 sec)

mysql> select card_id


-> from book_lending
-> where due_date between '01jan2017' and '01jun2017'
-> group by card_id
-> having count(*)>0;
Empty set (0.00 sec)

mysql>

You might also like