Dublin Core Application Profile for Scholarly Works Slainte
Final_DBMS_Project4
1. CS 561 Project4-Library Management System Shubham Gupta
1
The name of my project is Library Management System. The Users are-
1) Administrator
2) Faculty
3) Student
Users will require a unique id so that they are distinguishable from each other. Designation will have a
value fornon-administrators whichcanbe studentorfaculty andwill separate admins and non-admins.
Studentsand facultyrequiresthateverybookshouldhave a unique id so that each book can be tracked
separately and should be divided with respect to department so that it’s easier for them to search it.
The controller of the database requires unique borrow id for each borrow so that librarian can identify
the user and the book issued.
ID will be the ID provided by the college in the table Users. Book_ID will be maintained by the
administrator which will be known by the designation field in the table Users.
Bookid will be monitoredbythe adminwhichwe willknow throughthe designationfieldinthe users.
Bookid will be varchar.First2 characters forthe departmentandlast4 fieldwill be last4digitsof ISBN.
ID will be the ID providedbythe college inthe table Users.
The attributes required by the User’s table would be –
a) ID- To give a unique ID to every User and this will be the primary key.
b) Name-To know the name of the User.
c) Designation-To see whether the User is admin, student or teacher.
d) Book_ID-To see which User has Borrowed which book which is also a foreign key.
The attributes required by the Book’s table would be-
a) Book_ID- To uniquely identify each book in the library and is the primary key.
b) Title- To see the title of the book.
c) Department- To see which department the book belongs to so that its easier to find.
d) Author-To know who is the author of the book.
e) Available- The value tells whether the book is available or not. 1 is for available and 0 if its not
available.
The attributes of the Borrow table would be-
a) Borrow_ID- To issue a unique borrow id to each book issued and is the primary key.
b) Book_ID- Is the foreign key from table Book.
2. CS 561 Project4-Library Management System Shubham Gupta
2
c) ID- Is the foreign key from table User.
d) dateOfborrow- The date on which the book is issued.
e) Due_date- The date on which the book is due.
f) dateOfReturn- The date by which the book should be returned.
The following are the tables which will be required based on the needs of the users-
Users
Attribute name Data Type Size Constraints Cascading
Problems
ID Int 10 PRIMARY_KEY On delete
Name_user Varchar 20 CONSTRAINT_NAME
Designation Varchar 10 CONSTRAINT_NAME
Borrow_ID Int 10 FOREIGN_KEY
Primary Key(s):ID
ForeignKey(s):Borrow_ID references Borrow.
Indices: None
Books
Attribute name Data Type Size Constraints Cascading
Problems
book_ID Varchar 6 PRIMARY_KEY On delete
Title Varchar 20 CONSTRAINT_NAME
Department Varchar 10 CONSTRAINT_NAME
Author Varchar 20 CONSTRAINT_NAME
Available Boolean 1 Boolean
3. CS 561 Project4-Library Management System Shubham Gupta
3
Primary Key(s):book_ID
ForeignKey(s):None
Indices: None
Borrow
Attribute name Data Type Size Constraints Cascading
Problems
borrow_ID Int 10 PRIMARY_KEY
book_ID Varchar 10 FOREIGN_KEY,PRIMARY_KEY On delete
ID Int 10 FOREIGN_KEY,PRIMARY_KEY On update
dateOfBorrow Date Date Date
due_date Date Date Date
dateOfReturn Date Date Date
Primary Key(s): borrow_ID,book_ID,ID.
ForeignKey(s):book_IDreferencesBooks,IDreferencesUsers.
Indices: None
Un-Normalized Table:
Users(ID, Name,Designation,Borrow_ID,Book_ID, Title, Department,Author,Available,dateOfBorrow,
due_date, dateOfReturn)
1NF:
In 1NF all key attributes must be defined. All attributes are also dependent on the primary key.
Users(ID, Name,Designation, Borrow_ID,Book_ID,Title, Department,Author,Available,dateOfBorrow,
due_date, dateOfReturn)
2NF:
4. CS 561 Project4-Library Management System Shubham Gupta
4
For 2NF it shouldbe firstconvertedinto1 NF whichis alreadydone inthe firststep.In 2NF there should
be no partial dependency. So, partial dependencies are removed.
User (ID, Name, Designation)
Takes (ID, Borrow_ID)
Books (Book_ID, Title, Department, Author, Available)
Borrow (Book_ID, Borrow_ID, dateOfBorrow, due_date, dateOfReturn)
3NF:
For converting into 3NF, first it should be converted into 2NF which is done in the step above. In 3NF
transitive dependencies will be removed.
User (ID, Name, Designation)
Takes (ID, Borrow_ID)
Books (Book_ID, Title, Department, Author, Available)
Borrow (Book_ID, Borrow_ID, dateOfBorrow, due_date, dateOfReturn)
BCNF:
Asthe table isin3NF andit onlyas 1 keyattribute itisin BCNFbecause whenwe reachedtill 3NFwe got
rid of all partial and transitive dependencies.
User (ID, Name, Designation)
Takes (ID, Borrow_ID)
Books (Book_ID, Title, Department, Author, Available)
Borrow (Book_ID, Borrow_ID, dateOfBorrow, due_date, dateOfReturn)
5. CS 561 Project4-Library Management System Shubham Gupta
5
Code for creating the table-
create table Users
(ID integer, Name_user varchar(20), Designation varchar(10), primary key(ID) );
create table Books
(Book_ID varchar(6),Title varchar(20),Department varchar(10),Author varchar(20),Available boolean,
primary key (Book_ID));
create table Borrow
(Book_ID varchar(6),Borrow_ID integer,
dateOfBorrowdate, due_date date,dateOfReturndate,primarykey(Borrow_ID), foreignkey(Book_ID)
references Books);
create table Takes
(ID integer, Borrow_IDinteger,primarykey(ID,borrow_ID),foreignkey(ID) referencesUsers,foreignkey
(Borrow_ID) references Borrow );
Code for entering the values into the table-
Users
insert into Users values (1000,'Packard', 'student');
insert into Users values (1001,'Painter', 'student');
insert into Users values (4000,'Watson', 'faculty');
insert into Users values (5000,'Taylor', 'admin');
insert into Users values (1002,'Leo', 'student');
insert into Users values (4001,'Chaw', 'faculty');
Books
insert into Books values ('IS2000', 'Data Warehousing', 'IS','Dale','0');
insert into Books values ('CS2001', 'Algorithms', 'CS','Feff','0');
insert into Books values ('CE2002', 'Hardware Engg', 'CE','Jade','0');
6. CS 561 Project4-Library Management System Shubham Gupta
6
insert into Books values ('BI2003', 'Python', 'BI','Marc','1');
insert into Books values ('CS2004', 'Java', 'CS','Jun','1');
Borrow
insert into Borrow values ('IS2000', 3000, '5/8/2016','5/28/2016',’5/30/2016’);
insert into Borrow values ('CS2001', 3001, '5/8/2016','5/28/2016',null);
insert into Borrow values ('CE2002', 3002, '4/8/2016','4/28/2016','5/4/2016');
Takes
insert into Takes values (1000, 3000);
insert into Takes values (1001, 3001);
insert into Takes values (4000, 3002);
SQL quesries-
User- Admin
ques) Admin wants total number of members using the library management system.
Select count(id) as No_of_members from users where designation <> 'user';
7. CS 561 Project4-Library Management System Shubham Gupta
7
Ques) Show the details of the books issued on 4/8/2016.
select * from Books where Book_ID=(Select Book_ID from
Borrow where date_part('year',DateOfBorrow)=2016 and
date_part('month',DateOfBorrow)=4 and date_part('day',DateOfBorrow)=8);
8. CS 561 Project4-Library Management System Shubham Gupta
8
Ques) Show the borrow id and book id of users who have returned the books after the due date.
Select borrow_id,book_ID from Borrow where dateofreturn > due_date;
9. CS 561 Project4-Library Management System Shubham Gupta
9
Ques) Show the borrow id associated with the author Jun.
select Borrow_ID from Borrow where Book_ID=(Select Book_ID from Books where author='Jun');
10. CS 561 Project4-Library Management System Shubham Gupta
10
User- Student
Ques) Student wants to see all the books available in the CS department.
select title from books where department='CS';
11. CS 561 Project4-Library Management System Shubham Gupta
11
Ques) Student wants to see the date of borrow of the book whose title is algorithms.
selectDateOfBorrowfromBorrowwhereBook_ID=(selectBook_IDfromBookswheretitle='Algorithms');
12. CS 561 Project4-Library Management System Shubham Gupta
12
Ques) Student wants to see the ID of the user who has the book data warehousing.
Select ID from takes where
borrow_ID=(Select Borrow_ID from Borrow
where Book_ID= (select Book_ID from books where title='Data Warehousing'));
13. CS 561 Project4-Library Management System Shubham Gupta
13
User- Faculty
Ques) Faculty with id 4000 wants to see the title of the book issued by herself.
Select Title from books where book_Id=( Select Book_ID from borrow where borrow_ID = (select
borrow_ID from takes where id = '4000'));
14. CS 561 Project4-Library Management System Shubham Gupta
14
Ques) Faculty wants to see the date of return associated with title hardware engg.
select DateOfReturn from Borrow where Book_ID=(select Book_ID from Books where title='Hardware
Engg');
15. CS 561 Project4-Library Management System Shubham Gupta
15
Ques) Faculty wants to see the details of all the books in the library.
Select * from books;
16. CS 561 Project4-Library Management System Shubham Gupta
16
Some more queries-
Ques) Show all the issued books.
select * from books where available ='false';
17. CS 561 Project4-Library Management System Shubham Gupta
17
Ques) Show all the unissued books.
select * from books where available ='true';