0% found this document useful (0 votes)
69 views14 pages

ER Model

This document contains the entity relationship (ER) diagram and database schema for a library management system. It includes tables for books, members, and the relationship between them to track book loans. It also provides sample data and 15 SQL queries that analyze, update, and retrieve data from the tables.

Uploaded by

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

ER Model

This document contains the entity relationship (ER) diagram and database schema for a library management system. It includes tables for books, members, and the relationship between them to track book loans. It also provides sample data and 15 SQL queries that analyze, update, and retrieve data from the tables.

Uploaded by

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

ER-MODEL

LIBRARY
MANAGEMENT
SYSTEM

SUBMITTED BY-AGNEL PRINCE


COURSE- PGDDA
ROLL NUMBER-7
SUBJECT-DATABASE MANAGEMENT
SUBMITTED TO-PROF. SANJAY DHINGRA
ER DIAGRAM OF THE MODEL
TABLE FOR BOOK DETAILS
create table book
(book_id number(6) primary key,
title varchar(30) unique,
price number(5),
author char(20),
no_of_books number(5));

insert into book


values(1,'Anna Karenina',300,'Tolstoy',15);
insert into book
values(2,'Madame Bovary',200,'Gustav Flaubert',10);
insert into book
values(3,'Lolita',350,'Vladimir Nabokov',35);
insert into book
values(4,'Hamlet',100,'William Shakespeare',14);
insert into book
values(5,'Middlemarch',400,'George Eliot',50);
insert into book
values(6,'Pride and Prejudice',250,'Jane Austen',20);
insert into book
values(7,'Wuthering Heights',320,'Emily Bronte',30);
insert into book
values(8,'David Copperfield',500,'Charles Dickens',45);
insert into book
values(9,'Moby-Dick',280,'Herman Melville',15);
insert into book
values(10,'The Red and the Black',620,'Stendhal',36);
select * from book;

TABLE FOR MEMBER DETAILS


create table member
(name char(30),
memb_id number(10) primary key,
book_id number(5),
phone number(11) unique,
job char(25),
address varchar(30));

insert into member


values('AGNEL',100,1,8278912345,'doctor','42-D');
insert into member
values('MEHAK',101,3,9879912567,'clerk','84-A');
insert into member
values('JINO',102,1,9556433129,'doctor','83-C');
insert into member
values('SID',103,6,8897912443,'engineer','45-F');
insert into member
values('BRIAN',104,4,9776654321,'scientist','543-G');
insert into member
values('JENNA',105,5,8009723245,'clerk','42-A');
insert into member
values('LAURA',106,2,9897622334,'doctor','76-D');
insert into member
values('GINA',107,3,9994412388,'artist','56-H');
insert into member
values('BARNEY',108,5,8899965432,'scientist','79-A');
insert into member
values('JOEY',109,8,8770099553,'clerk','65-B');
select * from member;

TABLE FOR RELATIONSHIP


create table relationship
(issue_date date not null,
return_date date not null,
book_id number(5),
memb_id number(5),
foreign key(book_id) references book(book_id),
foreign key(memb_id) references member(memb_id));

insert into relationship


values(DATE'2022-01-01',DATE'2022-06-04',1,100);
insert into relationship
values(DATE'2022-03-04',DATE'2022-07-08',4,101);
insert into relationship
values(DATE'2022-02-03',DATE'2022-04-04',8,102);
insert into relationship
values(DATE'2022-05-06',DATE'2022-09-10',7,103);
insert into relationship
values(DATE'2022-01-10',DATE'2022-9-12',3,104);
insert into relationship
values(DATE'2022-06-06',DATE'2022-07-08',9,105);
insert into relationship
values(DATE'2022-03-03',DATE'2022-05-05',2,106);
select * from relationship;
SQL QUERIES
1. TO UPDATE THE NUMBER OF BOOKS
update book set no_of_books=24
where book_id=4;
select * from book where book_id=4;

2. TO DISPLAY DETAILS OF MEMBERS ACCORDING TO THE JOB


TITLES
select * from member where job='doctor' or job='clerk';
3. TO DISPLAY THE NUMBER OF MEMBERS OF EACH JOB TYPE.
select job,count(*) from member group by job;

4. TO ADD FOREIGN KEY CONSTRAINT ON BOOK_ID OF MEMBER


TABLE
alter table member
add constraint fk foreign key(book_id) references book(book_id);

5. TO GET DETAILS FROM BOTH THE TABLES


select name,job,title,author,memb_id from book,member where
book.book_id=member.book_id;
6.TO INCREASE THE NUMBER OF BOOKS WHICH ARE LESS THAN
20.
update book set no_of_books=15+no_of_books where no_of_books<20;
select * from book;
7.TO SHOW INTERSECTION I.E. COMMON BOOK ID IN BOTH
MEMBER AND BOOK TABLE
select book_id from book intersect select book_id from member;

8. TO FIND TOTAL NUMBER OF BOOKS IN THE LIBRARY


select sum(no_of_books) from book;
9. TO FIND THE TOTAL NUMBER OF DAYS THE MEMBER WITH
BOOK_ID=3 HAD THE BOOK WITH THEM.
select (return_date-issue_date) from relationship where book_id=3;

10. TO INCREASE THE NUMBER OF DAYS BY 5 FROM RETURN_DATE


OF MEMBER IDS 102 AND 104
select return_date+5 from relationship where memb_id=102 or memb_id=104;

11. TO ALTER TABLE RELATIONSHIP AND ADD A NEW COLUMN


ISSUE.
alter table relationship
add(issue number(5));
12. TO MODIFY ADDRESS IN MEMBER TABLE.
alter table member modify(address varchar(40));

13. TO DISPLAY RPAD IN TITLE OF TABLE BOOK.


select rpad(title,20,'.') from book;
14. TO DISPLAY THE SECOND OCCURRENCE OF A IN NAMES OF
MEMBERS
select instr(name,'A',1,2) from member;

15. TO SHOW TRANSLATE FUNCTION


select translate(1234567,1023456,'ABCDEFG') from member;

You might also like