Group Project
Group Members
Kh.Ibraheem -063
Abdul Kareem -143
Haris Mehmood -005
Section
Yellow (C)
Subject
Database
Submitted to
Miss. Iqra
Source Code
CREATE DATABASE my_library;
USE my_library;
CREATE TABLE user_id
user_name varchar(20),
pasword char(20)
);
CREATE TABLE book
book_id int not null primary key,
book_name varchar(20),
book_author varchar(20)
);
CREATE TABLE students
student_name varchar(20),
student_roll_number int not null primary key,
batch int,
department varchar(20),
semester char(10)
);
CREATE TABLE bookstatus --//Books availability
book_id int not null,
status_of_book varchar(11),
FOREIGN KEY (book_id) REFERENCES book(book_id)
);
CREATE TABLE record --//Books belonging to students
book_id int not null,
student_roll_number int not null,
FOREIGN KEY (book_id) REFERENCES book(book_id),
FOREIGN KEY (student_roll_number) REFERENCES students(student_roll_number)
);
INSERT INTO user_id(user_name, assword)
VALUES(‘Ibraheem’, ‘Saturday2020’),
(‘Abdul Kareem’, ‘database’),
(‘Haris Mehmood’, ‘day123’);
INSERT INTO book(book_id, book_name, book_author)
VALUES(1, ‘Database Systems’, ‘George Newman’),
(2, ‘Algorithms’, ‘Kevin Hart’),
(3, ‘Thoery Of Automata’, ‘John Conor’),
(4,’Chemistry’, ‘WD Bush’),
(5,’Physics’,’Charlie Hunman’);
ALTER TABLE book ADD book_count INT;
UPDATE book SET book_count= 10 WHERE book_id=1;
UPDATE book SET book_count= 10 WHERE book_id=2;
UPDATE book SET book_count= 10 WHERE book_id=3;
UPDATE book SET book_count= 10 WHERE book_id=4;
UPDATE book SET book_count= 10 WHERE book_id=5;
UPDATE book SET book_count= 12 WHERE book_id=5;
INSERT INTO students(student_name, student_roll_number, batch, department, semester)
VALUES (‘Aysha’, 20, 18, ‘Chemistry’, ‘1st’),
(‘Shoaib’, 29, 14, ‘Physics’, ‘3rd’),
(‘Hamza’, 78, 16, ‘IT’, ‘4th’),
(‘Saad’, 69, 18, ‘IT’, ‘6th’),
(‘Ali’,63, 17, ‘CS’, ‘2nd’);
INSERT INTO bookstatus(book_id, status_of_book)
VALUES(1, ‘Available’),
(2, ‘Available’),
(3, ‘Not Avail’),
(4, ‘Available’),
(5,’Not Avail’);
INSERT INTO record(book_id, student_roll_number)
VALUES(1, 20),
(1, 29),
(1, 63),
(1, 69),
(1, 78),
(2, 78),
(2, 29),
(2, 63),
(2, 20),
(2, 69),
(2, 78),
(3, 20),
(3, 29),
(3, 63),
(3, 69),
(3, 78),
(4, 20),
(4, 29),
(4, 63),
(4, 69),
(4, 78),
(5, 20),
(5, 29),
(5, 63),
(5, 69),
(5, 78);
delete record;
--//Tells user’s access
SELECT *FROM user_id;
--//Tells us about books id, name, author, num of books
SELECT *FROM book;
--//Tells us about students name, roll no., batch, department, semester
SELECT *FROM students;
--//Tells us about books availability
SELECT *FROM bookstatus;
--//Tells us about books given to students
SELECT *FROM record;
--//Shows students name in alphabetical order
SELECT *FROM students
ORDER BY student_name;
--//Shows students name with roll no. >50 using group by & having
SELECT COUNT(student_roll_number), student_name
FROM students
GROUP BY student_name
HAVING SUM(student_roll_number)>50;
--//Shows students with roll no. <50
SELECT COUNT(student_roll_number), student_name
FROM students
GROUP BY student_name
HAVING SUM(student_roll_number)<50;
--//Shows sum of all books using SUM
SELECT SUM(book_count)
FROM book;
--//Shows least books in library using MIN
SELECT MIN(book_count)
FROM book;
--//Shows most book in library using MAX
SELECT MAX(book_count)
FROM book;
--//Shows num of total students
SELECT COUNT(student_roll_number)
FROM students;
--//Shows books name and their totals using Group by
SELECT book_name, SUM(book_count)
FROM book Group By book_name;
--//Tells us books name and to student roll no. they belong to using CROSS JOIN
SELECT book_name, student_roll_number FROM book CROSS JOIN students;
--//Tells us book name and if they are available USING CROSS JOIN
SELECT book_name, status_of_book FROM book CROSS JOIN bookstatus;
Entity Relationship Diagram