1.
) create table books(book_id int(15) primary key,title varchar(255),author
varchar(100),published_year int(4),available_copies int(50));
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| title | varchar(255) | YES | | NULL | |
| author | varchar(100) | YES | | NULL | |
| published_year | int | YES | | NULL | |
| available_copies | int | YES | | NULL | |
+------------------+--------------+------+-----+---------+-------+
insert into books value(12,'atomic habits','james clear',2018,13),(03,'the psycology of money','morgan
housel',2020,07),(09,'too good to be true','prajakta koli',2021,19),(02,'a man called ove','fredrik
backman',2013,20);
+---------+------------------------+-----------------+----------------+------------------+
| book_id | title | author | published_year | available_copies |
+---------+------------------------+-----------------+----------------+------------------+
| 2 | a man called ove | fredrik backman | 2013 | 20 |
| 3 | the psycology of money | morgan housel | 2020 | 7|
| 9 | too good to be true | prajakta koli | 2021 | 19 |
| 12 | atomic habits | james clear | 2018 | 13 |
+---------+------------------------+-----------------+----------------+------------------+
create table students(student_id int(15) primary key,name varchar(10),roll_no varchar(10),course
varchar(50),contact int(11));
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| student_id | int | NO | PRI | NULL | |
| name | varchar(10) | YES | | NULL | |
| roll_no | varchar(10) | YES | | NULL | |
| course | varchar(50) | YES | | NULL | |
| contact | int | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
insert into students
value(03,'Dashanxi','a24cse003','btech(cse)',88668300),(37,'krisha','a24cse037','bca',85451908),(29,'kalp
','a24cse029','bca',93199178),(12,'aryan','a24cse012','btech(cse)',73595604);
+------------+----------+-----------+------------+----------+
| student_id | name | roll_no | course | contact |
+------------+----------+-----------+------------+----------+
| 3 | Dashanxi | a24cse003 | btech(cse) | 88668300 |
| 12 | aryan | a24cse012 | btech(cse) | 73595604 |
| 29 | kalp | a24cse029 | bca | 93199178 |
| 37 | krisha | a24cse037 | bca | 85451908 |
+------------+----------+-----------+------------+----------+
create table issued_books(issue_id int(10) primary key,student_id int(10),book_id int(10),issue_date
DATE,due_date DATE,return_status ENUM('Returned','NOT Returned'));
+---------------+---------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------------------------+------+-----+---------+-------+
| issue_id | int | NO | PRI | NULL | |
| student_id | int | YES | | NULL | |
| book_id | int | YES | | NULL | |
| issue_date | date | YES | | NULL | |
| due_date | date | YES | | NULL | |
| return_status | enum('Returned','NOT Returned') | YES | | NULL | |
+---------------+---------------------------------+------+-----+---------+-------+
insert into issued_books value(121,03,12,'2024-07-15','2024-08-03','NOT Returned'),(129,37,09,'2024-
06-10','2024-09-23','Returned'),(135,29,03,'2023-04-01','2024-04-19','Returned'),(140,12,02,'2023-01-
09','2023-12-27','NOT Returned');
+----------+------------+---------+------------+------------+---------------+
| issue_id | student_id | book_id | issue_date | due_date | return_status |
+----------+------------+---------+------------+------------+---------------+
| 121 | 3| 12 | 2024-07-15 | 2024-08-03 | NOT Returned |
| 129 | 37 | 9 | 2024-06-10 | 2024-09-23 | Returned |
| 135 | 29 | 3 | 2023-04-01 | 2024-04-19 | Returned |
| 140 | 12 | 2 | 2023-01-09 | 2023-12-27 | NOT Returned |
+----------+------------+---------+------------+------------+---------------+
create table library_staff(staff_id int(5) primary key,name varchar(100),designation
ENUM('librarian','clerk','technician'),contact varchar(10),join_date DATE,salary
DECIMAL(9,2),shift_timing ENUM('morning','evening'));
+--------------+----------------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------------------------------------+------+-----+---------+-------+
| staff_id | int | NO | PRI | NULL | |
| name | varchar(100) | YES | | NULL | |
| designation | enum('librarian','clerk','technician') | YES | | NULL | |
| contact | varchar(10) | YES | | NULL | |
| join_date | date | YES | | NULL | |
| salary | decimal(9,2) | YES | | NULL | |
| shift_timing | enum('morning','evening') | YES | | NULL | |
+--------------+----------------------------------------+------+-----+---------+-------+
insert into library_staff value(01,'Vishalbhai','librarian','7843219609','2022-06-
01','25000.89','morning'),(02,'Varshaben','librarian','9517438446','2023-11-
19','22750.45','evening'),(03,'Ketanbhai','clerk','7854126901','2023-04-
10','30270.00','evening'),(04,'Yashbhai','technician','9638520073','2022-11-23','20650.28','morning');
+----------+------------+-------------+------------+------------+----------+--------------+
| staff_id | name | designation | contact | join_date | salary | shift_timing |
+----------+------------+-------------+------------+------------+----------+--------------+
| 1 | Vishalbhai | librarian | 7843219609 | 2022-06-01 | 25000.89 | morning |
| 2 | Varshaben | librarian | 9517438446 | 2023-11-19 | 22750.45 | evening |
| 3 | Ketanbhai | clerk | 7854126901 | 2023-04-10 | 30270.00 | evening |
| 4 | Yashbhai | technician | 9638520073 | 2022-11-23 | 20650.28 | morning |
+----------+------------+-------------+------------+------------+----------+--------------+
2.) update students set roll_no="05" where name="Dashanxi";
+------------+----------+-----------+------------+----------+
| student_id | name | roll_no | course | contact |
+------------+----------+-----------+------------+----------+
| 3 | Dashanxi | 05 | btech(cse) | 88668300 |
| 12 | aryan | a24cse012 | btech(cse) | 73595604 |
| 29 | kalp | a24cse029 | bca | 93199178 |
| 37 | krisha | a24cse037 | bca | 85451908 |
+------------+----------+-----------+------------+----------+
3.) delete from library_staff where name="Ketanbhai";
+----------+------------+-------------+------------+------------+----------+--------------+
| staff_id | name | designation | contact | join_date | salary | shift_timing |
+----------+------------+-------------+------------+------------+----------+--------------+
| 1 | Vishalbhai | librarian | 7843219609 | 2022-06-01 | 25000.89 | morning |
| 2 | Varshaben | librarian | 9517438446 | 2023-11-19 | 22750.45 | evening |
| 4 | Yashbhai | technician | 9638520073 | 2022-11-23 | 20650.28 | morning |
+----------+------------+-------------+------------+------------+----------+--------------+
4.) select count(*),designation from library_staff group by designation;
+----------+-------------+
| count(*) | designation |
+----------+-------------+
| 2 | librarian |
| 1 | technician |
+----------+-------------+
5.) select * from issued_books order by student_id;
+----------+------------+---------+------------+------------+---------------+
| issue_id | student_id | book_id | issue_date | due_date | return_status |
+----------+------------+---------+------------+------------+---------------+
| 121 | 3 | 12 | 2024-07-15 | 2024-08-03 | NOT Returned |
| 140 | 12 | 2 | 2023-01-09 | 2023-12-27 | NOT Returned |
| 135 | 29 | 3 | 2023-04-01 | 2024-04-19 | Returned |
| 129 | 37 | 9 | 2024-06-10 | 2024-09-23 | Returned |
+----------+------------+---------+------------+------------+---------------+
6.) select * from issued_books order by student_id desc;
+----------+------------+---------+------------+------------+---------------+
| issue_id | student_id | book_id | issue_date | due_date | return_status |
+----------+------------+---------+------------+------------+---------------+
| 129 | 37 | 9 | 2024-06-10 | 2024-09-23 | Returned |
| 135 | 29 | 3 | 2023-04-01 | 2024-04-19 | Returned |
| 140 | 12 | 2 | 2023-01-09 | 2023-12-27 | NOT Returned |
| 121 | 3 | 12 | 2024-07-15 | 2024-08-03 | NOT Returned |
+----------+------------+---------+------------+------------+---------------+
7.) create view new_view as select student_id,name,course from students;
select * from new_view;
+------------+----------+------------+
| student_id | name | course |
+------------+----------+------------+
| 3 | Dashanxi | btech(cse) |
| 12 | aryan | btech(cse) |
| 29 | kalp | bca |
| 37 | krisha | bca |
+------------+----------+------------+
8.) select * from issued_books limit 3;
+----------+------------+---------+------------+------------+---------------+
| issue_id | student_id | book_id | issue_date | due_date | return_status |
+----------+------------+---------+------------+------------+---------------+
| 121 | 3 | 12 | 2024-07-15 | 2024-08-03 | NOT Returned |
| 129 | 37 | 9 | 2024-06-10 | 2024-09-23 | Returned |
| 135 | 29 | 3 | 2023-04-01 | 2024-04-19 | Returned |
+----------+------------+---------+------------+------------+---------------+
9.) select * from issued_books limit 1,2;
+---------+------------+------------+---------------+
| issue_id | student_id | book_id | issue_date | due_date | return_status |
+----------+------------+---------+------------+------------+---------------+
| 129 | 37 | 9 | 2024-06-10 | 2024-09-23 | Returned |
| 135 | 29 | 3 | 2023-04-01 | 2024-04-19 | Returned |
+----------+------------+---------+------------+------------+---------------+
10.) select name from students where student_id = 3;
+----------+
| name |
+----------+
| Dashanxi |
+----------+
11.) select name from library_staff where name like 'V_%';
+------------+
| name |
+------------+
| Vishalbhai |
| Varshaben |
+------------+
12.) select title,book_id from books where published_year>2018 and available_copies<15;
+------------------------+---------+
| title | book_id |
+------------------------+---------+
| the psycology of money | 3|
+------------------------+---------+
13.) select title,book_id from books where published_year>2018 or available_copies<20;
+------------------------+---------+
| title | book_id |
+------------------------+---------+
| the psycology of money | 3|
| too good to be true | 9|
| atomic habits | 12 |
+------------------------+---------+
14.) select title,book_id from books where not available_copies<8;
+---------------------+---------+
| title | book_id |
+---------------------+---------+
| a man called ove | 2|
| too good to be true | 9|
| atomic habits | 12 |
+---------------------+---------+
15.) select * from library_staff where(salary between 22000 and 27000);
+----------+------------+-------------+------------+------------+----------+--------------+
| staff_id | name | designation | contact | join_date | salary | shift_timing |
+----------+------------+-------------+------------+------------+----------+--------------+
| 1 | Vishalbhai | librarian | 7843219609 | 2022-06-01 | 25000.89 | morning |
| 2 | Varshaben | librarian | 9517438446 | 2023-11-19 | 22750.45 | evening |
+----------+------------+-------------+------------+------------+----------+--------------+
16.) drop table library_staff;