24
Library Database Name: database systems Section: COMP-344-1-CRN:20121 Department: Electrical & Computer Engineering Term: Spring 2014 / 2015 Instructor(s): Hamed Mohamed Nassar Student name: Mohammad Bilal Salloum Student ID: 210302354

DB_S15_LIBPH3_Mohammad_Salloum

Embed Size (px)

Citation preview

Library Database

Name: database systems

Section: COMP-344-1-CRN:20121

Department: Electrical & Computer Engineering

Term: Spring 2014 / 2015

Instructor(s): Hamed Mohamed Nassar

Student name: Mohammad Bilal Salloum

Student ID: 210302354

Requirements: We will store for each book an ID, a title and its availability. Each book will be categorized and

will have a specific publisher, author(s) and a supplier. Each category will have an ID and name Each publisher will have an ID, name and a phone number Suppliers will have an ID, name and phone number We will store all of our transactions. Each transaction will have an ID, borrow date and deadline

for return date. The transaction will contain lines and will be received by a borrower the transaction likes will be stored with IDs in a log book that will hold the return date and the

log book is identified by its year Each borrower will have an ID, address name and phone number which will all be stored in the

log book

ER

1

2

Publisher

Category

borrower

Line

Book

Supplier

Writes

Borrower

ID Name Phone1 Charles David 1715069112 Stepheny Mayor 11225463 J.K. Rowling 10531132794 Stephen King 15107845295 Andrew Mathew 2550146896 Mostafa

Humaidy152014587

7 Adnan Ibrahim 15287401838 Oliver Bowden 12087641959 Jessica Blair 112470932810 Mostafa Baydoun 1617185472

ID

Name Phone

1 Pearson 15245682 Monza 53421873 Nelson 534175414 Gibli 154287545 Hyperion Books 543178456 Lennon 5431234

ID

Book_ID Trans_ID

1 2 13 4 35 6 56 8 79 9 98 11 82 12 24 15 47 17 610 21 10

ID Name Phone1000 Mohammad Salloum 15248371001 Jamal Abed 152478691002 Mariam Sawas 187456391003 Moataz Khaled 107489631004 Ammar Armashi 104764821005 Rania Malkawi 102486841006 Mahmoud Kharisha 148239541007 Michael Hani 193528461008 John Hani 145239781009 David Bekham 24563871010 Ali Makki 10879361011 Raya'an Yafi 101010101012 Osama Abdo 12462871013 Ali Al Wafi 14015861014 Mahmood Ayman 123456781015 Mahdi Bazzi 1852346

Author_ID

Book_ID

1 41 71 182 22 63 74 34 144 175 86 16 46 126 207 58 98 139 159 169 1910 1010 11

ID

Title Publisher_IDCatergoy_ID Supplier_ID

1 Pride and Prejudice 2 1 22 The glory 1 8 13 Munchease 2 3 24 Today and forever 4 4 35 My Mathbook 1 2 26 Ordinary door 3 10 27 Doom 4 6 18 Valid Vacation 5 5 39 No one 3 3 210 Twilight 3 9 211 Wizard of OZ 1 3 212 Name me 2 7 113 Komono 3 9 214 Love Life 4 4 215 What and who to eat 5 2 316 Begin the world 1 7 317 The Lord Of the Rings 2 3 218 Star Wars 3 2 319 The Lightning Thief 4 4 120 World of Ants 2 10 321 The Notebook 1 1 2

ID Name1 Romance2 Scientific3 Fantasy4 Engineering5 Mystrey6 Classics7 Thriller8 Horror9 Humour10 Young Readers

ID

Borrower_ID Borrow_datedeadline

1 1000 2015-03-01 2015-04-012 1008 2015-03-02 2015-04-023 1003 2015-03-01 2015-04-014 1014 2015-03-11 2015-04-115 1011 2015-03-19 2015-04-196 1015 2015-03-04 2015-04-047 1005 2015-03-03 2015-04-038 1000 2015-03-06 2015-04-069 1014 2015-03-08 2015-04-0810 1010 2015-03-10 2015-04-10

ID

Name Address PhoneQuantity_supplied

1 Malik's Hamra Street 12354380 02 Antoine Hamra Street 87654154 03 Books Plus Verdun 13154878 0

Relational schema:

s

ID

Name

ID

Title Publisher_ID Catergory_ID

Supplier_ID

ID

Name Phone

ID Book_ID

Trans_ID

3

book

borrower

category

line

publisher

supplier

writes

author

ID

Name Phone

ID

Name Address PhoneQuantity_supplied

ID

Name

Author_ID

Book_ID

4

transaction

ID Borrower_ID

Borrow_date

deadline

Relation’s schemaAuthor:

Publisher:

Supplier:

Book:

5

ID

Name Phone

ID

Name Phone

ID Title

ID

Name Phone

Category:

Borrower:

Transaction:

Line: (Weak entity)

Writes: (Mapping a many to many relation)

6

ID

Name

ID

Name Phone

ID Borrower_ID

ID Book_ID

Trans_ID

Author_ID

Book_ID

Queries

Publisher:

ID

Name Phone

1 Pearson 15245682 Monza 53421873 Nelson 534175414 Gibli 154287545 Hyperion Books 54317845

Query:INSERT INTO publisher VALUES (6,"Lennon",5431234);Result:

Query:

UPDATE author

7

ID Name Phone1 Charles David 1715069112 Stepheny Mayor 11225463 J.K. Rowling 10531132794 Stephen King 15107845295 Andrew Mathew 2550146896 Mostafa

Humaidy152014587

7 Adnan Ibrahim 15287401838 Oliver Bowden 12087641959 Jessica Blair 112470932810 Mostafa Baydoun 1617185472

SET Phone = 255012458Where ID = 2

Result:

8

AuthorWrites

ID Title Publisher_ID Catergoy_ID Supplier_ID1 Pride and Prejudice 2 1 22 The glory 1 8 13 Munchease 2 3 24 Today and forever 4 4 35 My Mathbook 1 2 26 Ordinary door 3 10 27 Doom 4 6 18 Valid Vacation 5 5 39 No one 3 3 210 Twilight 3 9 211 Wizard of OZ 1 3 212 Name me 2 7 113 Komono 3 9 214 Love Life 4 4 215 What and who to eat 5 2 316 Begin the world 1 7 317 The Lord Of the Rings 2 3 218 Star Wars 3 2 319 The Lightning Thief 4 4 120 World of Ants 2 10 321 The Notebook 1 1 2

Author_ID

Book_ID

1 41 71 182 22 63 74 34 144 175 86 16 46 126 207 58 98 139 159 169 1910 1010 11

ID Name Phone1 Charles David 1715069112 Stepheny Mayor 11225463 J.K. Rowling 10531132794 Stephen King 15107845295 Andrew Mathew 2550146896 Mostafa Humaidy 1520145877 Adnan Ibrahim 15287401838 Oliver Bowden 12087641959 Jessica Blair 112470932810 Mostafa Baydoun 1617185472

Query: (Which writer wrote what book) SELECT author.Name , book.TitleFROM author , book , writesWHERE writes.Book_ID = book.ID AND writes.Author_ID = author.IDEquivalent to: π (author.Name , book.Title)(σ<writes.Book_ID=book.ID AND writes.Author_ID =

author.ID>(author,book,writes)

Result:

9

Publisher

ID

Title Publisher_IDCatergoy_ID Supplier_ID

1 Pride and Prejudice 2 1 22 The glory 1 8 13 Munchease 2 3 24 Today and forever 4 4 35 My Mathbook 1 2 26 Ordinary door 3 10 27 Doom 4 6 18 Valid Vacation 5 5 39 No one 3 3 210 Twilight 3 9 211 Wizard of OZ 1 3 212 Name me 2 7 113 Komono 3 9 214 Love Life 4 4 215 What and who to eat 5 2 316 Begin the world 1 7 317 The Lord Of the Rings 2 3 218 Star Wars 3 2 319 The Lightning Thief 4 4 120 World of Ants 2 10 321 The Notebook 1 1 2

ID

Name Phone

1 Pearson 15245682 Monza 53421873 Nelson 534175414 Gibli 154287545 Hyperion Books 543178456 Lennon 5431234

Query:(which publisher published what)SELECT book.Title , publisher.Name FROM book , publisher WHERE book.Publisher_ID = publisher.ID

Equivalent to: π (book.Titles,publisher.Name)(σ<book.Publisher_ID=publisher.ID>(book,publisher)

Result:

10

Borrower

ID Name Phone1000 Mohammad Salloum 15248371001 Jamal Abed 152478691002 Mariam Sawas 187456391003 Moataz Khaled 107489631004 Ammar Armashi 104764821005 Rania Malkawi 102486841006 Mahmoud Kharisha 148239541007 Michael Hani 193528461008 John Hani 145239781009 David Bekham 24563871010 Ali Makki 10879361011 Raya'an Yafi 101010101012 Osama Abdo 12462871013 Ali Al Wafi 14015861014 Mahmood Ayman 123456781015 Mahdi Bazzi 1852346

ID

Title Publisher_IDCatergoy_ID Supplier_ID

1 Pride and Prejudice 2 1 22 The glory 1 8 13 Munchease 2 3 24 Today and forever 4 4 35 My Mathbook 1 2 26 Ordinary door 3 10 27 Doom 4 6 18 Valid Vacation 5 5 39 No one 3 3 210 Twilight 3 9 211 Wizard of OZ 1 3 212 Name me 2 7 113 Komono 3 9 214 Love Life 4 4 215 What and who to eat 5 2 316 Begin the world 1 7 317 The Lord Of the Rings 2 3 218 Star Wars 3 2 319 The Lightning Thief 4 4 120 World of Ants 2 10 321 The Notebook 1 1 2

Query:(Who ordered what book)

SELECT borrower.Name , Book.TitleFROM book , borrower , line , transaction WHERE line.Trans_ID = transaction.ID AND line.Book_ID = book.ID AND transaction.Borrower_ID = borrower.ID

Equivalent to: π (borrower.Name,Book.Title)(σ <line.Trans_ID=transaction.ID AND line.Book_ID=book.ID AND transaction.Borrower_ID

=borrower.ID>(book,publisher)

Result

11

Line

ID

Book_ID Trans_ID

1 2 13 4 35 6 56 8 79 9 98 11 82 12 24 15 47 17 610 21 10

A different Approach

Requirements Each book is identified by Book number (ID). Each has a title.

Each book has one author, and can be borrowed from one or more member at different date.

Each book can be identified by one or more from these three categories: Novel, Junior and Journals.

Each Novel has Genre. Each junior has a Reading age. Each Journal has Editor.

Each Member is identified by a SSN. Each has a Name and Date Of birth. And can borrow one book or more.

Enhanced ER diagram:

12

Book

O

Novel JournalsJunior

Reading age Genre Editor

Member

d

Adult SeniorJunior

School Work University

SSN Name DOB

BorrowNM

Relation’s schema:

1. Mapping Specialization:

2. Mapping Entity:

13

3. Mapping Many to Many Relationship:

14

Relational Schema

15

Tables:

16

Queries

1) Display all journals

BookId Title Author

1 The Lion and the Witch

Rayan Hamonn

2 The glory Mariam Hamed

3 Munchease Jacob Havoc

4 Today and Forever

J.K. Rowling

5 Science Boy

Mclean Murphy

Query: SELECT book.Title

17

BookId Editor3 Jacob Havoc5 Molly Murphy

FROM book , journalWHERE book.BookId = journal.BookId

Result:Title

MuncheaseScience Boy

18

2) Borrow log

SELECT member.Name,book.Title,borrow.Date FROM book,member,borrow WHERE book.BookId=borrow.BookID AND member.SSN=borrow.SSN

Result:Name Title DateCharles David The Lion and the Witch 2015-05-15David Beckham The Lion and the Witch 2015-02-10Maria Perry The glory 2015-05-19Charles David The glory 2015-05-10Nelson Mandela The glory 2015-05-24David Beckham Munchease 2015-01-20Mike Stanley Today and Forever 2015-05-03Nelson Mandela Today and Forever 2015-05-23Mike Stanley Science Boy 2015-05-02

19

BookId Title Author1 The Lion

and the Witch

Rayan Hamonn

2 The glory Mariam Hamed3 Munchease Jacob Havoc4 Today and

ForeverJ.K. Rowling

5 Science Boy

Mclean Murphy

SSN Name DOB1 Maria Perry 1994-05-05

3 Charles David

1993-08-27

4 Mike Stanley

1993-02-28

5 Nelson Mandela

1995-07-14

6 David Beckham

1990-11-26

SSN BookID Date1 2 2015-05-193 2 2015-05-103 1 2015-05-154 5 2015-05-024 4 2015-05-036 3 2015-01-206 1 2015-02-105 2 2015-05-245 4 2015-05-23

Name Title DateCharles David The Lion and the Witch 2015-05-15David Beckham The Lion and the Witch 2015-02-10Maria Perry The glory 2015-05-19Charles David The glory 2015-05-10Nelson Mandela The glory 2015-05-24David Beckham Munchease 2015-01-20Mike Stanley Today and Forever 2015-05-03Nelson Mandela Today and Forever 2015-05-23Mike Stanley Science Boy 2015-05-02

20