Our fictional bookshop is located in Hertford, England (a very real and charming town north of London). It is located in a building constructed around 1735 and has two rather smallish rooms on two floors with floor-to-ceiling bookshelves throughout. Upon entering, one is immediately transported to a much earlier era being quite overwhelmed by the wonderful sight and odor of the ancient mahogany wood in which the entire interior is lined along with the rare and ancient books that reside on them. There is a little bell that announces one's entrance into the shop but it is not really needed, as the delightfully squeaky floor boards quite clearly makes your presence known.
In spite of the ancient setting and very old and rare books, this bookshop has a very modern Internet storefront through which it sells and auctions off its expensive inventory. A computer system contains a database describing the inventory and manages the sales and auction processes. The database schema for our bookshop is given below.
create table acctmgr( mgrid char(7) primary key, name char(24), hire_date date, commission decimal(4,3) ); create table patron( patid char(3) primary key, name char(30), street char(35), city char(17), state char(2), country char(2), pc char(10), email char(63), phone char(15), mgrid char(7) references acctmgr on update cascade ); create table author( last_name char(13) primary key, full_name char(35), gender char(1), yr_born smallint, yr_died smallint, short_bio varchar(216), constraint yob_gender_key key (yr_born, gender) ); create table genres( text char(31) primary key ); create table subjects( text char(51) primary key ); create table book( bookid char(14) primary key, last_name char(13) references author on delete cascade on update cascade, title varchar(105) key, descr char(61), publisher varchar(136), publ_year smallint key, lc_class char(33), date_acqd date, date_sold date, price decimal(10,2), cost decimal(10,2) ); create table related_name( bookid char(14) references book on delete cascade on update cascade, name char(61) ); create table genres_books( bookid char(14) references book on delete cascade on update cascade, genre char(31) references genres ); create table subjects_books( bookid char(14) references book on delete cascade on update cascade, subject char(51) references subjects ); create table note( noteid integer primary key, bookid char(14) references book on delete cascade on update cascade, patid char(3) references patron on delete cascade on update cascade ); create table note_line( noteid integer references note on delete cascade on update cascade, text char(61) ); create table sale( bookid char(14) references book on delete cascade on update cascade, patid char(3) references patron on delete cascade on update cascade ); create table auction( aucid integer primary key, bookid char(14) references book on delete cascade on update cascade, mgrid char(7) references acctmgr on update cascade, start_date date, end_date date, reserve decimal(10,2), curr_bid decimal(10,2), bid_time time ); create table bid( aucid integer references auction on delete cascade on update cascade, patid char(3) references patron on delete cascade on update cascade, offer decimal(10,2), bid_ts timestamp );
Descriptions for each of the above tables are given below.
|author||Each row contains biographical information about a renowned author.|
|book||Contains information about each book in the bookshop inventory. The last_name column associates the book with its author. Books with a non null date_sold are no longer available.|
|genres||Table of genre names (e.g., "Historical fiction") with which particular books are associated via the genres_books table.|
|subjects||Table of subject names (e.g., "Cape Cod") with which particular books are associated via the subjects_books table.|
|related_name||Related names are names of individuals associated with a particular book. The names are usually hand-written in the book's front matter or on separate pages that were included with the book (e.g., letters) and identify the book's provenance (owners). Only a few books have related names. However, their presence can significantly increase the value of the book.|
|genres_books||Used to create a many-to-many relationship between genres and books.|
|subjects_books||Used to create a many-to-many relationship between subjects and books.|
|note||Connects each note_line to its associated book. Notes include edition info and other comments (often coded) relating to its condition.|
|note_line||One row for each line of text in a particular note.|
|acctmgr||Account manager are the bookshop employees responsible for servicing the patrons and managing auctions.|
|patron||Bookshop customers and their contact info. Connected to their purchases/bids through their relationship with the sale and auction tables.|
|sale||Contains one row for each book that has been sold. Connects the book with the patron who acquired through the bookid and patid columns.|
|auction||Some books are auctioned. Those that have been (or currently being) auctioned have a row in this table that identifies the account manager who oversees the auction. The reserve column specifies the minimum acceptable bid, curr_bid contains the current amount bid.|
|bid||Each row provides the bid history for a particular auction.|
Foreign keys are declared using the REFERENCES clause. Many are specified with the ON DELETE/UPDATE CASCADE option indicating that deletions or updates to the referenced rows will cause the referencing row to automatically be deleted or updated as well.
A schema diagram depicting the inter-table relationships is shown below. As was mentioned above for the NSF awards database, the arrows represent a one-to-many relationship between the source and target tables and labels on the arrows identify the foreign key in the target table on which the relationship is formed.
Figure 6 - Bookshop Database Schema Diagram
The sample data that is included with this example contains book descriptions that were obtained from the United States Library of Congress online card catalog: http://catalog.loc.gov. The short biographical sketches included with each author entry are condensed descriptions from information about each author contained on Wikipedia: http://www.wikipedia.org. The use of the Wikipedia information is governed by the Creative Commons Attribution-ShareAlike license: http://creativecommons.org/licenses/by-sa/3.0/. Pricing information and the JPEG files of photographs of some of the books in the database were obtained from the website for Peter Harrington Antiquarian Bookseller in Chelsea London, http://www.peterharrington.co.uk, which is a perfect real-world example of the kind of bookshop depicted in this example.