Download PowerPoint

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
UTS Library Database
Ankur Kandikatla
HD Assignment 3, Autumn 2007
UTS Library Database



This database aims to model the UTS library
system, with simplification
Has information about borrowers, their
memberships, library branches , staff and books
Particular focus on the transaction aspect of
database, i.e. checking out of books
UTS Library Database ERD
1:m Relationship
Catalogue
Book
BookID
CatalogueNo*
Borrow Type
BranchID*
Contains
CatalogueNo
Title
Publisher
AFirstName
ALastName
Year
Catalogue – Books
Catalogue
Catalogue
No
Title
Year
005.74
KORT
(ED.5)
Database
System
Concepts
2006
2006
005.7585
WELS
Everyday
Oracle
DBA
…
…
…
Book
Foreign key
Other
columns
CatalogueNo
BookID
BorrowType
005.74 KORT
(ED.5)
1
Standard
005.74 KORT
(ED.5)
2
Standard
005.74 KORT
(ED.5)
3
7 Day Loan
005.7585
WELS
1
Closed
Reserve
m:m Relationship
CheckOut
Borrow Item
CheckOutNo
DateOut
Borrow erID*
BookID*
CheckOutNo*
CatalogueNo*
DateReturn
BookID
CatalogueNo*
Borrow Type
BranchID*
CheckOut-Books
CheckOut
CheckOut
No
Book
DateOut
BorowerID
BorrowItem
m:m relationship
1
1-Apr-2007
3
CatalogueNo
2
3-Mar-2007
2
1
1
15-Apr-2007
3
6-May-2007
4
005.74 KORT
(ED.5)
4
18-May-2007
6
005.74 CHAO
2
1
17-Apr-2007
Books
CatalogueNo
BookID
BorrowType
OtherColumns
005.74 KORT (ED.5)
1
Standard
..
005.74 KORT (ED.5)
2
Standard
..
005.74 CHAO
2
7 Day
Loan
..
BookID
CheckOutNo
DateReturn
Single Table Query
Selecting a few items from the catalogue
SELECT CatalogueNo, Title
FROM Catalogue;
catalogueno
|
title
--------------------+------------------------------------005.74 KORT (ED.5) | Database System Concepts
005.74 CHAO
| Database Development and Management
005.74 POWE
| Beginning Database Design
005.7585 WELS
| Everyday Oracle DBA
658.872 KUMA
| Mobile Database Systems
(5 rows)
NATURAL JOIN
Identifying the branch of staff members
SELECT SFirstName, SLastName, BranchID
FROM Staff NATURAL JOIN LibBranch;
sfirstname | slastname | branchid
------------+------------+----------Colin
| Richardson | City
Kathy
| Jays
| KuringGai
Neeraj
| Matta
| City
David
| Tong
| KuringGai
Mushfika
| Hossain
| City
Tat
| Nguyen
| City
Mark
| Bonnett
| City
(7 rows)
NATURAL JOIN (Cross Product)
Identifying the branch of staff members
SELECT SFirstName, SLastName, Staff.BranchID
FROM Staff, LibBranch
WHERE Staff.BranchId = LibBranch.BranchId;
sfirstname | slastname | branchid
------------+------------+----------Colin
| Richardson | City
Kathy
| Jays
| KuringGai
Neeraj
| Matta
| City
David
| Tong
| KuringGai
Mushfika
| Hossain
| City
Tat
| Nguyen
| City
Mark
| Bonnett
| City
(7 rows)
GROUP BY
The number of books issued in each check out transaction
SELECT CheckOutNo, count(*) as Books
FROM BorrowedItem
GROUP BY CheckOutNo;
checkoutno | books
------------+------1 |
2
2 |
2
3 |
1
4 |
3
(4 rows)
Sub Query
The name of the borrowers who have checked out more than two
books in one transaction
SELECT BFirstName, BLastName
FROM Borrower NATURAL JOIN Checkout
WHERE checkoutno =
(SELECT CheckOutNo FROM BorrowedItem GROUP BY CheckOutNo HAVING
Count(*)>2);
bfirstname | blastname
------------+----------Anna
| Cameron
(1 row)
Self Join
Finding two books by the same publisher
SELECT c1.Title, c2.Title, c1.Publisher, c1.Year
FROM Catalogue c1, Catalogue c2
WHERE c1.Publisher = 'Wiley'
AND c2.Publisher = 'Wiley'
AND c1.CatalogueNo > c2.CatalogueNo;
-[ RECORD
title
title
publisher
year
1
|
|
|
|
]-----------------------Mobile Database Systems
Beginning Database Design
Wiley
2006
Check Statements
Checking for book borrow type
CONSTRAINT Book_BorrowType CHECK
(BorrowType IN ('7 Day Loan', 'Closed Reserve', 'Standard'))
Checking for Postcode
CONSTRAINT LibPostcode_Range CHECK
((LibPostcode >= 1000) AND (LibPostcode <=9999))
Action Statements
On Delete Restrict
CONSTRAINT fk_Staff FOREIGN KEY(BranchID) REFERENCES
LibBranch(BranchID)
ON DELETE RESTRICT
ON UPDATE CASCADE
On Delete Cascade
CONSTRAINT fk_BorrowerMembership FOREIGN KEY(BorrowerID)
REFERENCES Borrower(BorrowerID)
ON DELETE CASCADE
ON UPDATE CASCADE
Views

Creating a view for 7 Day Loan books
CREATE VIEW SevDayLoan(CatalogueNo, Title, BookID, BorrowType,
Branch)
AS SELECT Book.CatalogueNo, Title, BookID, BorrowType, BranchID
FROM Book NATURAL JOIN Catalogue
WHERE BorrowType = '7 Day Loan';

Selecting 7 Day Loan books available in the City Campus
SELECT CatalogueNo, Title, BookID, Branch
FROM SevDayLoan WHERE Branch='City';
catalogueno
|
title
| bookid | branch
--------------------+---------------------------+--------+---005.74 KORT (ED.5) | Database System Concepts |
3 | City
005.74 POWE
| Beginning Database Design |
2 | City
658.872 KUMA
| Mobile Database Systems
|
2 | City
658.872 KUMA
| Mobile Database Systems
|
3 | City
(4 rows)
Related documents