0% found this document useful (0 votes)
59 views20 pages

Visit:: Join Telegram To Get Instant Updates: Contact: MAIL: Instagram: Instagram

This document provides the schema and SQL queries for a Library Database management system. It includes: 1) The schema diagram showing the tables - BOOK, BOOK_AUTHORS, PUBLISHER, BOOK_COPIES, BOOK_LENDING, LIBRARY_BRANCH. 2) SQL queries to create the tables based on the schema. 3) SQL insert statements to populate the tables with sample data. The document gives all the necessary information to design, create and populate the tables for a Library Database using SQL.

Uploaded by

study material
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views20 pages

Visit:: Join Telegram To Get Instant Updates: Contact: MAIL: Instagram: Instagram

This document provides the schema and SQL queries for a Library Database management system. It includes: 1) The schema diagram showing the tables - BOOK, BOOK_AUTHORS, PUBLISHER, BOOK_COPIES, BOOK_LENDING, LIBRARY_BRANCH. 2) SQL queries to create the tables based on the schema. 3) SQL insert statements to populate the tables with sample data. The document gives all the necessary information to design, create and populate the tables for a Library Database using SQL.

Uploaded by

study material
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Visit : https://hemanthrajhemu.github.

io

Join Telegram to get Instant Updates: https://bit.ly/2GKiHnJ

Contact: MAIL: [email protected]

INSTAGRAM: www.instagram.com/hemanthraj_hemu/

INSTAGRAM: www.instagram.com/futurevisionbie/
1|Page https://hemanthrajhemu.github.io

[As per Choice Based Credit System (CBCS) scheme]


(Effective from the academic year 2017-2018)
SEMESTER – V
Subject Code:17CSL58 IA Marks: 40
Exam Marks: 60 Exam Hours: 03
----------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------
Consider the following schema for a Library Database:
BOOK (Book_id, Title, Publisher_Name, Pub_Year)
BOOK_AUTHORS (Book_id, Author_Name)
PUBLISHER (Name, Address, Phone)
BOOK_COPIES (Book_id, Branch_id, No-of_Copies)
BOOK_LENDING (Book_id, Branch_id, Card_No, Date_Out, Due_Date)
LIBRARY_BRANCH (Branch_id, Branch_Name, Address)
Write SQL queries to:
1. Retrieve details of all books in the library – id, title, name of publisher,
authors, number of copies in each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3
books, but from Jan 2017 to Jun 2017.
3. Delete a book in BOOK table. Update the contents of other tables to
reflect this data manipulation operation.
4. Partition the BOOK table based on year of publication. Demonstrate its
working with a simple query.
5. Create a view of all books and its number of copies that are currently
available in the Library.

https://hemanthrajhemu.github.io
2|Page https://hemanthrajhemu.github.io

----------------------------------------------------------------------------------------------
SCHEMA DIAGRAM:
--------------------------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
3|Page https://hemanthrajhemu.github.io

-------------------------------------------------------------------------------------------------------

STEPS TO OPEN THE ORACLE DATABASE – 10G


EXPRESS EDITION
-------------------------------------------------------------------------------------------------------
Step 1: Open the Browser (Preferred Chrome).
Step 2: http://127.0.0.1:8080/ Enter the link on the browser.
Step 3: login with your id and password (finding difficulty in login in go to the
link to know in-depth details
https://hemanthrajhemu.github.io/FutureVisionBIE/WP/5CSE/DBMS_LAB_INFO.html

(Note Username is the system by default & Password is the passkey you entered
in the installation)

Step 4: Now click on SQL->SQL Commands. This is the place where we execute
the SQL Commands.

Step 5: you are in SQL Command Now you can Create table, create view, Run
Queries here & lot more.

https://hemanthrajhemu.github.io
4|Page https://hemanthrajhemu.github.io

-------------------------------------------------------------------------------------------------------
Create Table: (Follow the Schema Diagram in Creating the Data Base)
-------------------------------------------------------------------------------------------------------
1. Create Table for PUBLISHER
CREATE TABLE PUBLISHER
(NAME VARCHAR(20) PRIMARY KEY,
ADDRESS VARCHAR(50) NOT NULL,
PHONE INTEGER);

NOW RUN.

2. Create Table for BOOK


CREATE TABLE BOOK
(BOOK_ID INTEGER PRIMARY KEY,
TITLE VARCHAR(20) NOT NULL,
PUBLISHER_NAME VARCHAR(20)
REFERENCES PUBLISHER(NAME)
ON DELETE CASCADE,
PUB_YEAR VARCHAR(5));

Now Click on Run.

https://hemanthrajhemu.github.io
5|Page https://hemanthrajhemu.github.io

3. Create Table for BOOK_AUTHOR


CREATE TABLE BOOK_AUTHOR
(BOOK_ID INTEGER
REFERENCES BOOK(BOOK_ID)
ON DELETE CASCADE,
AUTHOR_NAME VARCHAR(20) NOT NULL,
PRIMARY KEY(BOOK_ID));

Click on Run.

4. Create Table for LIBRARY_BRANCH


CREATE TABLE LIBRARY_BRANCH
(BRANCH_ID INTEGER PRIMARY KEY,
BRANCH_NAME VARCHAR(20) NOT NULL,
ADDRESS VARCHAR(50) );

Click on Run.

5. Create Table for BOOK_LENDING


CREATE TABLE BOOK_LENDING
(BOOK_ID INTEGER
REFERENCES BOOK(BOOK_ID)
ON DELETE CASCADE,
BRANCH_ID INTEGER
REFERENCES
LIBRARY_BRANCH(BRANCH_ID)
ON DELETE CASCADE,
CARD_NO INTEGER NOT NULL,
DATE_OUT DATE NOT NULL,
DUE_DATE DATE,
PRIMARY KEY(BOOK_ID,BRANCH_ID));

Click on Run.

https://hemanthrajhemu.github.io
6|Page https://hemanthrajhemu.github.io

6. Create Table for BOOK_COPIES


CREATE TABLE BOOK_COPIES
(BOOK_ID INTEGER
REFERENCES BOOK(BOOK_ID)
ON DELETE CASCADE,
BRANCH_ID INTEGER
REFERENCES
LIBRARY_BRANCH(BRANCH_ID),
NO_OF_COPIES INTEGER,
PRIMARY KEY(BOOK_ID,BRANCH_ID) );

Click on Run.

-------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
7|Page https://hemanthrajhemu.github.io

-------------------------------------------------------------------------------------------------------
TABLE DESCRIPTION
-------------------------------------------------------------------------------------------------------
1. DESC PUBLISHER;

2. DESC BOOK;

https://hemanthrajhemu.github.io
8|Page https://hemanthrajhemu.github.io

3. DESC BOOK_AUTHOR;

4. DESC LIBRARY_BRANCH;

https://hemanthrajhemu.github.io
9|Page https://hemanthrajhemu.github.io

5. DESC BOOK_LENDING;

6. DESC BOOK_COPIES;

-------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
10 | P a g e https://hemanthrajhemu.github.io

-------------------------------------------------------------------------------------------------------
INSERTION OF VALUES TO TABLE
-------------------------------------------------------------------------------------------------------
1. VALUES INTO PUBLISHER
INSERT INTO PUBLISHER VALUES(<NAME> , <ADDRESS>, <PHONE> );
INSERT INTO PUBLISHER VALUES('PEARSON','NEW DELHI',9996621456);
INSERT INTO PUBLISHER VALUES(‘OXFORD’,‘MUMBAI’,9966884422);
INSERT INTO PUBLISHER VALUES(‘MC GRAW HILL’,‘CHENNAI’, 8866333444);
INSERT INTO PUBLISHER VALUES(‘O_REILLY’,‘MANGLORE’,9898989898);
INSERT INTO PUBLISHER VALUES(‘APRESS & DREAMTECH’,‘MAHARASTRA’,
9876549876);

2. VALUES INTO BOOK


INSERT INTO BOOK
VALUES(<BOOK_ID>,<TITLE>,<PUBLISHER_NAME>,<PUB_YEAR> );
INSERT INTO BOOK VALUES(2001,'DBMS','PEARSON','2015');
INSERT INTO BOOK VALUES(2002,'COMPUTER NETWORKS','OXFORD','2019');
INSERT INTO BOOK VALUES(2003,'JAVA','MC GRAW HILL','2016');
INSERT INTO BOOK VALUES(2004,'C PROGRAMMING','O_REILLY','2014');
INSERT INTO BOOK VALUES(2005,'PHP','APRESS & DREAMTECH','2017');

https://hemanthrajhemu.github.io
11 | P a g e https://hemanthrajhemu.github.io

3. VALUES INTO BOOK_AUTHOR


INSERT INTO BOOK_AUTHOR VALUES(<BOOK_ID>,<AUTHOR_NAME>);
INSERT INTO BOOK_AUTHOR VALUES(2001,’KANISHKA BEDI’);
INSERT INTO BOOK_AUTHOR VALUES(2002,’POORNIMA M’);
INSERT INTO BOOK_AUTHOR VALUES(2003,’P C TRIPATHI’);
INSERT INTO BOOK_AUTHOR VALUES(2004,’P N REDDY’);
INSERT INTO BOOK_AUTHOR VALUES(2005,’VISHWA KIRAN’);

4. VALUES INTO LIBRARY_BRANCH


INSERT INTO LIBRARY_BRANCH
VALUES(<BRANCH_ID>,<BRANCH_NAME>,<ADDRESS>);
INSERT INTO LIBRARY_BRANCH VALUES(3001,'R T NAGAR','BANGLORE');
INSERT INTO LIBRARY_BRANCH
VALUES(3002,'MALESHWARAM','BANGLORE');
INSERT INTO LIBRARY_BRANCH VALUES(3003,'SECTOR 21','NODIA');
INSERT INTO LIBRARY_BRANCH VALUES(3004,'KLS INSTITUTE','BELGAUM');
INSERT INTO LIBRARY_BRANCH VALUES(3005,'YELAHANKA','BANGLORE');

https://hemanthrajhemu.github.io
12 | P a g e https://hemanthrajhemu.github.io

5. VALUES INTO BOOK_LENDING


INSERT INTO BOOK_LENDING
VALUES(<BOOK_ID>,<BRANCH_ID>,<CARD_NO>,<DATE_OUT>,<DUE_DATE>
);
INSERT INTO BOOK_LENDING VALUES('2001','3001','4001','02-JAN-2017','02-
FEB-2017');
INSERT INTO BOOK_LENDING VALUES('2002','3001','4001','07-JAN-2017','07-
FEB-2017');
INSERT INTO BOOK_LENDING VALUES('2003','3001','4001','10-JAN-2017','10-
FEB-2017');
INSERT INTO BOOK_LENDING VALUES('2004','3001','4001','20-JAN-2017','20-
FEB-2017');
INSERT INTO BOOK_LENDING VALUES('2005','3002','4005','20-JAN-2017','20-
FEB-2017');

6. VALUES INTO BOOK_COPIES


INSERT INTO BOOK_COPIES
VALUES(<BOOK_ID>,<BRANCH_ID>,<NO_OF_COPIES>);
INSERT INTO BOOK_COPIES VALUES(2001,3001,10);
INSERT INTO BOOK_COPIES VALUES(2002,3001,10);
INSERT INTO BOOK_COPIES VALUES(2003,3001,10);
INSERT INTO BOOK_COPIES VALUES(2003,3002,10);
INSERT INTO BOOK_COPIES VALUES(2002,3002,10);
INSERT INTO BOOK_COPIES VALUES(2001,3005,10);

-------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
13 | P a g e https://hemanthrajhemu.github.io

-------------------------------------------------------------------------------------------------------
RETRIEVAL OF INSERTED VALUES
-------------------------------------------------------------------------------------------------------
1. PUBLISHER:
SELECT * FROM PUBLISHER;
2. BOOK:
SELECT * FROM BOOK;

3. BOOK_AUTHOR:
SELECT * FROM BOOK_AUTHOR;
4. LIBRARY_BRANCH
SELECT * FROM LIBRARY_BRANCH;

https://hemanthrajhemu.github.io
14 | P a g e https://hemanthrajhemu.github.io

5. BOOK_LENDING:
SELECT * FROM BOOK_LENDING;
6. BOOK_COPIES:
SELECT * FROM BOOK_COPIES;

-------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
15 | P a g e https://hemanthrajhemu.github.io

-------------------------------------------------------------------------------------------------------
QUERIES
-------------------------------------------------------------------------------------------------------
1. Retrieve details of all books in the library – id, title, name of
publisher, authors, number of copies in each branch, etc.
SELECT B.BOOK_ID, B.TITLE, B.PUBLISHER_NAME, A.AUTHOR_NAME,
C.NO_OF_COPIES, C.BRANCH_ID
FROM BOOK B, BOOK_AUTHOR A, BOOK_COPIES C
WHERE B.BOOK_ID=A.BOOK_ID AND B.BOOK_ID=C.BOOK_ID;

---------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
16 | P a g e https://hemanthrajhemu.github.io

2. Get the particulars of borrowers who have borrowed more than 3


books, but from Jan 2017 to Jun 2017.
SELECT L.CARD_NO
FROM BOOK_LENDING L
WHERE DATE_OUT BETWEEN '01-JAN-2017' AND '01-JUL-2017'
GROUP BY L.CARD_NO
HAVING COUNT (CARD_NO)>3;

------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
17 | P a g e https://hemanthrajhemu.github.io

3. Delete a book in BOOK table. Update the contents of other tables to


reflect this data manipulation operation.
SELECT * FROM BOOK;

DELETE FROM BOOK WHERE BOOK_ID=2004;

SELECT * FROM BOOK;

https://hemanthrajhemu.github.io
18 | P a g e https://hemanthrajhemu.github.io

------------------------------------------------------------------------------------------------------
4. Partition the BOOK table based on year of publication. Demonstrate
its working with a simple query.
CREATE VIEW VW_PUB_YEAR AS
SELECT PUB_YEAR FROM BOOK;

SELECT * FROM VW_PUB_YEAR;

------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io
19 | P a g e https://hemanthrajhemu.github.io

5. Create a view of all books and its number of copies that are currently
available in the Library.
CREATE VIEW VW_BK_COPIES AS
SELECT B.BOOK_ID, B.TITLE,
C.NO_OF_COPIES
FROM BOOK B,BOOK_COPIES C
WHERE B.BOOK_ID=C.BOOK_ID;

SELECT * FROM VW_BK_COPIES;

-------------------------------------------------------------------------------------------------------
THE END
-------------------------------------------------------------------------------------------------------

https://hemanthrajhemu.github.io

You might also like