Practical 10
Practical 10
10
Create schema library;
Create tables:(books,issued_book,fine,student)
Create commands:
Create table books
(bookid int primary key,
title varchar (255),
author varchar (30),
subject varchar (30),
publisher varchar (30),
edition int,
price double);
create table student
(roll_no int primary key,
name varchar (30),
branch varchar (5),
year int);
Insert commands:
INSERT INTO books
VALUES
('120', 'Database Management System', 'KORTH', 'Computer', 'PHI', '3', '450.50'),
('121','Compiler Design', 'SILVER', 'Computer', 'PEARSON', '1', '350.00'),
('122', 'Programming in C', 'DENNIS', 'Computer', 'PHI', '2', '345.89'),
('124', 'Automata', 'SILVER', 'Computer', 'SUDARSHAN', '2', '760.0'),
('125', 'Engineering Physics', 'SK CHAND', 'Applied', 'MCGRAW', '2', '560.0'),
('127', 'Engineering Mathematics', 'SK CHAND', 'Applied', 'SUDARSHAN', '3', '600.0'),
('131', 'Management of Human', 'Fenny', 'Management', 'MGY', '2', '1200.50');
INSERT INTO student
values
('1', 'ahaan', 'AS', '1'),
('2', 'viaan', 'AS', '2'),
('3', 'sam', 'MGT', '2'),
('4', 'john', 'EC', '1'),
('5', 'loki', 'EC', '2'),
('6', 'robert', 'CSE', '1'),
('7', 'james', 'CSE', '3');
Queries:
1.Select all books
SELECT * FROM books;
2.Select all students
SELECT * FROM student;
20. Select books and the count of times each has been borrowed:
26. Select students who borrowed books with details of the book and edition:
SELECT s.*, ib.*, b.Title, b.Edition
FROM student s
JOIN issued_book ib ON s.Roll_No = ib.Roll_No
JOIN books b ON ib.BookID = b.BookID;
27. Find the books with editions greater than 2 borrowed by students:
28. List all books along with the fine details (if any):
SELECT b.*, f.*
FROM books b
LEFT JOIN fine f ON b.BookID = f.BookID;
30. List the names of students and the titles of books they have borrowed:
SELECT s.*, b.Title
FROM student s
JOIN issued_book ib ON s.Roll_No = ib.Roll_No
JOIN books b ON ib.BookID = b.BookID;