File

advertisement
Book Market
30 November 2011
Richard Saldivar
Richard Howe
Scott Pieper
Cameron Asbell
Table of Contents
Table of Contents
….....................................................................................2
1 Introduction and
Purpose........................................................................3
2 Database Organization and
Overview....................................................4
2.1 Business
Rules...................................................................................4
2.2 Entity Relationship
Diagram.............................................................5
3 Database Design
3.1 Data
Dictionary................................................................................6
3.2 SQL
Statements................................................................................8
3.3 Sample SQL
Statements..................................................................14
4 Summary of
Project...............................................................................15
2
1 Introduction and Purpose
The Book Market is a retail book seller seeking to create a web-based database
application to facilitate online customer purchases. An online store is a virtual store
where customers can browse for items, add them to a shopping cart and purchase
items from the convenience of home. At the point of purchase the customer will have
to provide further details such as name, address and payment details. They are
provided with a confirmation number as well as shipping details to complete the
transaction. As more and more businesses move towards online sales the process of
web based purchasing is becoming more and more commonplace.
The store has an existing database in place but it is not suitable for the store’s
endeavors to launch an online book store. Therefore the store needs an affordable
interactive database that will allow expansion as their business grows. The website
must be easy to use and comprehend by the user and contain all of the functionality
required by the retailer. The database will be required to provide the retailer with
the ability to control inventory by tracking the sales of items and determining which
items sell best. The records concerning each item should include title, author, ISBN
and any other details to specifically identify the inventory. Customer details such as
names, addresses and credit card information are essential to the database. Records
of items sold to individuals as well as the date of purchase are also important to the
database design. It should have the following functionality:





Organize and store related information about customers in the form of
customer name, street address, city, state, credit card information, purchase
date, shipping date.
Provide a public website where customers may search for and purchase items.
Ensure that the website provides easy navigation from the home page and the
linked items are in logical categorical order.
Provide a user friendly interface for authorized users of the book seller to
access data and make changes to the database.
Allow for ease of system management, maintenance and expansion.
In order to create a website for the Book Market it is essential to begin by
designing the relational database. The data model must be designed based on user
needs and the attributes required for the database. A data model is a conceptual
representation of the data found within a database. This model will serve as a
blueprint to map out the relationships between the different data sets that will be
used by Book Market to fulfill customer orders. Within the relational database will
be stored all of the related data about books, customers, billing and shipping that are
integral to the daily functions of the online bookstore. It is important that the
relational database is designed with the needs of all users as the primary focus. The
second part will be the design of a website that easily connects the customers to the
3
database in a way that is pleasing for the customer and maintains the integrity of the
database.
2 Database Organization Overview
2.1 Business Rules
The Book Market database is governed by the following general business rules:





Each customer can have more than one assigned credit card, but each credit
card must be assigned to only one customer.
Each credit card can be used to pay for more than one invoice, but each
invoice must be paid by only one credit card.
Each invoice can have more than one line item, but each line item must
correspond to only one invoice.
Each book can appear on multiple line items, but each line item must
reference only one book.
Each book can have one or more authors and each author can write one or
more books.
2.2 Entity Relationship Diagram
A database designer’s first obligation is to consult with representatives of all
potential users of a database and gain an understanding of the entities that will be
required. The Book Market’s online store will have the following tables:
1. AUTHOR: Represents the full name of the person who is credited with the
creation of a work of text.
2. BOOK: Represents a set or collection of written, printed or illustrated
pages fastened together and designated as a single work.
3. BOOK AUTHOR: Represents the relationship between an individual book and
an author.
4. CUSTOMER: Represents a person who engages in a purchase with the Book
Market Online bookstore.
5. CUSTOMER CREDIT CARD: Represents the payment authorized by the
individual customer along with the details of the card itself.
6. INVOICE: Represents a detailed list of goods shipped or services rendered,
with an account of all costs.
7. LINE ITEM: Represents a unit of information in a record shown on a
separate line of its own often referring to a separately identifiable budget
element.
4
Figure 1 Entity Relationship Diagram (ERD)
5
3 Database Design
3.1 Data Dictionary
Table
Name
Attribute Name
Contents
CUSTOMER
CUST_ID
Unique
Number
Assigned
to
Customer
Customer
First
Name
Customer
Middle
Name
Customer
Last
Name
Customer
Address
CUST_FNAME
CUST_MNAME
CUST_LNAME
CUST_ADDRESS
CUST_CITY
CUST_STATE
CUST_ZIP
CUST_AREACOD
E
CUST_PHONE
CUST_EMAIL_AD
DRESS
CUST_CRE
DIT_CARD
CUST_PASSWOR
D
CUST_CREDIT_ID
Customer
City
Customer
State
Customer
Zip Code
Customer
Area
Code
Customer
Phone
Number
Customer
E-mail
Address
Customer
Password
Unique
Number
Assigned
to
Customer
Credit
Card
Data
DATA DICTIONARY
Data
Data
Type
Forma
t
INTEGER #####
#
Range
Require
d
19999999
Y
VARCHAR
(15)
Xxxxx
xxx
N/A
N
VARCHAR
(15)
Xxxxx
xxx
N/A
N
VARCHAR
(15)
Xxxxx
xxx
N/A
N
VARCHAR
(35)
N/A
N
VARCHAR
(15)
CHAR(2)
9999
Xxxxx
x
Xxxxx
xxx
XX
N/A
N
N/A
N
CHAR(5)
99999
N/A
N
CHAR(3)
999
N/A
N
CHAR(8)
9999999
N/A
N
VARCHAR
(25)
xxxx@
xxxx
N/A
N
VARCHAR
(15)
INTEGER
xxxxxx
x
#####
##
N/A
N
19999999
Y
6
PK
or
FK
PK
PK
FK
Reference
d Table
Table
Name
Attribute Name
Contents
CUST_ID
Unique
Number
Assigned
to
Customer
Credit
Card
Company
Credit
Card
Number
Credit
Card
Verificati
on
Number
Expiratio
n Date
CUST_CREDIT_T
YPE
CUST_CREDIT_N
UM
CUST_CREDIT_C
CV
CUST_CREDIT_E
XPIRATION
INVOICE
INVOICE_ID
CUST_CREDIT_ID
INVOICE_DATE
INVOICE_SHIP_D
ATE
LINE_ITEM
INVOICE_ID
BOOK_ID
LINE_ITEM_QUA
NT
DATA DICTIONARY
Data
Data
Type
Forma
t
INTEGER #####
##
Range
Require
d
19999999
Y
PK
or
FK
FK
VARCHAR
(20)
Xxxxx
xxx
N/A
N
VARCHAR
(16)
99999
99…
N/A
N
VARCHAR
(4)
9999
N/A
N
DATE
yyyymmdd
#####
##
N/A
N
19999999
Y
PK
INTEGER
#####
##
19999999
Y
FK
DATE
yyyymmdd
ddmmyyyy
#####
##
N/A
N
N/A
N
19999999
Y
Unique
Number
Assigned
to
Invoice
Unique
Number
Assigned
to
Customer
Credit
Card
Data
Invoice
Date
INTEGER
Invoice
Shipping
Date
Unique
Number
Assigned
to
Invoice
Unique
Number
Assigned
to Book
DATE
Book
Quantity
INTEGER
INTEGER
INTEGER
7
#####
##
#####
19999999
0-9999
Y
N
PK
(Co
mpo
site)
FK
PK
(Co
mpo
site)
FK
FK
Reference
d Table
CUSTOMER
CUST_CRED
IT_CARD
INVOICE
BOOK
Table
Name
Attribute Name
Contents
BOOK
BOOK_ID
Unique
Number
Assigned
to Book
Book
ISBN
Book
Title
Book
Year of
Publicati
on
Book
Price
Unique
Number
Assigned
to Author
BOOK_ISBN
BOOK_TITLE
BOOK_PUB_YEA
R
BOOK_PRICE
BOOK_AUT
HOR
AUTHOR_ID
BOOK_ID
AUTHOR
AUTHOR_ID
AUTHOR_FNAME
AUTHOR_MNAME
AUTHOR_LNAME
DATA DICTIONARY
Data
Data
Type
Forma
t
INTEGER #####
##
Range
Require
d
19999999
Y
VARCHAR
(15)
VARCHAR
(100)
YEAR
99999
99…
Xxxxx
xxx
9999
N/A
N
N/A
N
N/A
N
FLOAT(7,
2)
INTEGER
####.#
#
#####
##
0.009999.00
19999999
N
Unique
Number
Assigned
to Book
INTEGER
Unique
Number
Assigned
to Author
Author’s
First
Name
Author’s
Middle
name
Author’s
Last
Name
INTEGER
#####
##
19999999
Y
VARCHAR
(15)
Xxxxx
xxx
N/A
N
VARCHAR
(15)
Xxxxx
xxx
N/A
N
VARCHAR
(15)
Xxxxx
xxx
N/A
N
3.2 SQL Statements
#
#Create customer table and structure
#
CREATE TABLE CUSTOMER
(CUST_ID INTEGER NOT NULL AUTO_INCREMENT,
CUST_FNAME VARCHAR(15),
CUST_MNAME VARCHAR(15),
CUST_LNAME VARCHAR(15),
CUST_ADDRESS VARCHAR(35),
8
#####
##
19999999
Y
Y
PK
or
FK
PK
PK
(Co
mpo
site)
FK
PK
(Co
mpo
site)
FK
PK
FK
Reference
d Table
AUTHOR
BOOK
CUST_CITY VARCHAR(15),
CUST_STATE CHAR(2),
CUST_ZIP CHAR(5),
CUST_AREACODE CHAR(3),
CUST_PHONE CHAR(8),
CUST_EMAIL_ADDRESS VARCHAR(25),
CUST_PASSWORD VARCHAR(15),
PRIMARY KEY (CUST_ID));
#
#Create cust_credit_card table and structure
#
CREATE TABLE CUST_CREDIT_CARD
(CUST_CREDIT_ID INTEGER NOT NULL AUTO_INCREMENT,
CUST_ID INTEGER NOT NULL,
CUST_CREDIT_TYPE VARCHAR(20) NOT NULL,
CUST_CREDIT_NUM VARCHAR(16) NOT NULL,
CUST_CREDIT_CCV VARCHAR(4) NOT NULL,
CUST_CREDIT_EXPIRATION DATE NOT NULL,
PRIMARY KEY (CUST_CREDIT_ID));
#
#Add foreign key to cust_credit_card table from customer table
#
ALTER TABLE CUST_CREDIT_CARD
ADD FOREIGN KEY (CUST_ID)
REFERENCES CUSTOMER(CUST_ID);
#
#Create book table and structure
#
CREATE TABLE BOOK
(BOOK_ID INTEGER NOT NULL AUTO_INCREMENT,
BOOK_ISBN VARCHAR(15),
BOOK_TITLE VARCHAR(100),
BOOK_PUB_YEAR YEAR,
BOOK_PRICE FLOAT(7,2),
PRIMARY KEY (BOOK_ID));
#
#Create Author table and structure
#
CREATE TABLE AUTHOR
(AUTHOR_ID INTEGER NOT NULL AUTO_INCREMENT,
AUTHOR_FNAME VARCHAR(15),
AUTHOR_MNAME VARCHAR(15),
AUTHOR_LNAME VARCHAR(15),
PRIMARY KEY (AUTHOR_ID));
#
#Create book_author table and structure
#
CREATE TABLE BOOK_AUTHOR
(AUTHOR_ID INTEGER NOT NULL,
BOOK_ID INTEGER NOT NULL,
9
PRIMARY KEY (AUTHOR_ID, BOOK_ID));
#
#Add foreign key to book_author table from author table
#
ALTER TABLE BOOK_AUTHOR
ADD FOREIGN KEY (AUTHOR_ID)
REFERENCES AUTHOR(AUTHOR_ID);
#
#Add foreign key to book_author table from book table
#
ALTER TABLE BOOK_AUTHOR
ADD FOREIGN KEY (BOOK_ID)
REFERENCES BOOK(BOOK_ID);
#
#Create invoice table and structure
#
CREATE TABLE INVOICE
(INVOICE_ID INTEGER NOT NULL AUTO_INCREMENT,
CUST_CREDIT_ID INTEGER NOT NULL,
INVOICE_DATE DATE,
INVOICE_SHIP_DATE DATE,
PRIMARY KEY (INVOICE_ID));
#
#Add foreign key to invoice table from customer credit card table
#
ALTER TABLE INVOICE
ADD FOREIGN KEY (CUST_CREDIT_ID)
REFERENCES CUST_CREDIT_CARD(CUST_CREDIT_ID);
#
#Create line_item table and structure
#
CREATE TABLE LINE_ITEM
(INVOICE_ID INTEGER NOT NULL,
BOOK_ID INTEGER NOT NULL,
LINE_ITEM_QUANT INTEGER NOT NULL,
PRIMARY KEY (INVOICE_ID, BOOK_ID));
#
#Add foreign key to line_item table from invoice table
#
ALTER TABLE LINE_ITEM
ADD FOREIGN KEY (INVOICE_ID)
REFERENCES INVOICE(INVOICE_ID);
#
#Add foreign key to line_item table from book table
#
ALTER TABLE LINE_ITEM
ADD FOREIGN KEY (BOOK_ID)
10
REFERENCES BOOK(BOOK_ID);
#
#Insert data into customer table
#
INSERT INTO CUSTOMER (CUST_FNAME, CUST_MNAME, CUST_LNAME, CUST_ADDRESS, CUST_CITY,
CUST_STATE, CUST_ZIP, CUST_AREACODE, CUST_PHONE, CUST_EMAIL_ADDRESS, CUST_PASSWORD)
VALUES ('Richard', 'Lewis', 'Saldivar', '123 Maple Ln', 'Smyrna', 'GA', '30080', '678', '999-8222',
'rlsaldivar@valdosta.edu', 'secretpassword');
INSERT INTO CUSTOMER (CUST_FNAME, CUST_MNAME, CUST_LNAME, CUST_ADDRESS, CUST_CITY,
CUST_STATE, CUST_ZIP, CUST_AREACODE, CUST_PHONE, CUST_EMAIL_ADDRESS, CUST_PASSWORD)
VALUES ('Michael', 'L.', 'Smith', '625 Peachtree St', 'Atlanta', 'GA', '30050', '770', '535-8999',
'mlsmith@gmail.com', 'puppy13');
INSERT INTO CUSTOMER (CUST_FNAME, CUST_LNAME, CUST_ADDRESS, CUST_CITY, CUST_STATE,
CUST_ZIP, CUST_AREACODE, CUST_PHONE, CUST_EMAIL_ADDRESS, CUST_PASSWORD) VALUES ('Susan',
'Jolie', '9888 North Ave', 'Marietta', 'GA', '30008', '678', '599-9988', 'suziej@yahoo.com', 'letmein');
INSERT INTO CUSTOMER (CUST_FNAME, CUST_MNAME, CUST_LNAME, CUST_ADDRESS, CUST_CITY,
CUST_STATE, CUST_ZIP, CUST_AREACODE, CUST_PHONE, CUST_EMAIL_ADDRESS, CUST_PASSWORD)
VALUES ('Allison', 'K.', 'Anderson', '3010 Hill St', 'Dallas', 'TX', '75217', '469', '282-9132',
'akand@gmail.com', '12345');
INSERT INTO CUSTOMER (CUST_FNAME, CUST_LNAME, CUST_ADDRESS, CUST_CITY, CUST_STATE,
CUST_ZIP, CUST_AREACODE, CUST_PHONE, CUST_EMAIL_ADDRESS, CUST_PASSWORD) VALUES ('Joe',
'Rosario', '234 Main St', 'Tampa', 'FL', '33612', '813', '872-1121', 'josario1422@yahoo.com', 'puppy');
INSERT INTO CUSTOMER (CUST_FNAME, CUST_MNAME, CUST_LNAME, CUST_ADDRESS, CUST_CITY,
CUST_STATE, CUST_ZIP, CUST_AREACODE, CUST_PHONE, CUST_EMAIL_ADDRESS, CUST_PASSWORD)
VALUES ('Anne', 'Kathleen', 'Johnson', '6323 Cumberland Blvd', 'Knoxville', 'TN', '37901', '865', '443-9932',
'akjohnson999@gmail.com', 'password1111');
#
#Insert data into cust_credit_card table
#
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (1, 'American Express', '387211111122555',
'5566', '2013-07-01');
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (2, 'Visa', '5382888811119988', '333', '2013-0501');
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (2, 'American Express', '387288888855555',
'8899', '2011-05-01');
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (3, 'Master Card', '889922599886131', '898',
'2014-01-01');
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (5, 'Visa', '5382998813439891', '917', '2013-0701');
11
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (4, 'Visa',
'8912418389930181', '888', '2014-08-01');
INSERT INTO CUST_CREDIT_CARD (CUST_ID, CUST_CREDIT_TYPE, CUST_CREDIT_NUM,
CUST_CREDIT_CCV, CUST_CREDIT_EXPIRATION) VALUES (6, 'Master Card',
'889922599812345', '712', '2015-09-01');
#
#Insert data into book table
#
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('006112009X', 'One Hundred Years of Solitude', '2006', 11.55);
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('1423902017', 'Database Systems: Design, Implementation, and Management', '2007', '147.49');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('0142000655', 'East of Eden', '2002', '11.56');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('1416059512', 'Atlas of Human Anatomy', '2010', '67.99');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('0679744398', 'All the Pretty Horses', '1993', '10.20');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('1613820836', 'Siddhartha', '2011', '6.99');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('0345409469', 'The Demon-Haunted World: Science as a Candle in the Dark', '1997', '11.56');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('0781790697', 'Langman''s Medical Embryology', '2009', '49.46');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('0143039431', 'The Grapes of Wrath', '2006', '10.88');
INSERT INTO BOOK (BOOK_ISBN, BOOK_TITLE, BOOK_PUB_YEAR, BOOK_PRICE)
VALUES ('0307387895', 'The Road', '2007', '10.20');
#
#Insert data into Author table
#
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_MNAME, AUTHOR_LNAME)
VALUES ('Gabriel', 'Garcia', 'Marquez');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('Peter', 'Rob');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('Carlos', 'Coronel');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('John', 'Steinbeck');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_MNAME, AUTHOR_LNAME)
12
VALUES ('Frank', 'H.', 'Netter');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('Cormac', 'McCarthy');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('Hermann', 'Hesse');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('Carl', 'Sagan');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_LNAME) VALUES ('Ann', 'Druyan');
INSERT INTO AUTHOR (AUTHOR_FNAME, AUTHOR_MNAME, AUTHOR_LNAME)
VALUES ('Thomas', 'W.', 'Sadler');
#
#Insert data into book_author table
#
INSERT INTO BOOK_AUTHOR VALUES (1, 1);
INSERT INTO BOOK_AUTHOR VALUES (2, 2);
INSERT INTO BOOK_AUTHOR VALUES (3, 2);
INSERT INTO BOOK_AUTHOR VALUES (4, 3);
INSERT INTO BOOK_AUTHOR VALUES (5, 4);
INSERT INTO BOOK_AUTHOR VALUES (6, 5);
INSERT INTO BOOK_AUTHOR VALUES (7, 6);
INSERT INTO BOOK_AUTHOR VALUES (8, 7);
INSERT INTO BOOK_AUTHOR VALUES (9, 7);
INSERT INTO BOOK_AUTHOR VALUES (10, 8);
INSERT INTO BOOK_AUTHOR VALUES (4, 9);
INSERT INTO BOOK_AUTHOR VALUES (6, 10);
#
#Insert data into invoice table
#
INSERT INTO INVOICE (CUST_CREDIT_ID, INVOICE_DATE, INVOICE_SHIP_DATE)
VALUES (1, '2011-11-11', '2011-11-18');
INSERT INTO INVOICE (CUST_CREDIT_ID, INVOICE_DATE, INVOICE_SHIP_DATE)
VALUES (2, '2011-11-12', '2011-11-18');
INSERT INTO INVOICE (CUST_CREDIT_ID, INVOICE_DATE)
VALUES (4, '2011-11-14');
INSERT INTO INVOICE (CUST_CREDIT_ID, INVOICE_DATE, INVOICE_SHIP_DATE)
13
VALUES (1, '2011-11-14', '2011-11-19');
INSERT INTO INVOICE (CUST_CREDIT_ID, INVOICE_DATE)
VALUES (5, '2011-11-15');
#
#Insert data into line_item table
#
INSERT INTO LINE_ITEM VALUES (1, 1, 2);
INSERT INTO LINE_ITEM VALUES (2, 2, 1);
INSERT INTO LINE_ITEM VALUES (2, 3, 1);
INSERT INTO LINE_ITEM VALUES (2, 10, 1);
INSERT INTO LINE_ITEM VALUES (3, 7, 1);
INSERT INTO LINE_ITEM VALUES (4, 9, 3);
INSERT INTO LINE_ITEM VALUES (5, 4, 1);
INSERT INTO LINE_ITEM VALUES (5, 7, 1);
INSERT INTO LINE_ITEM VALUES (5, 8, 1);
INSERT INTO LINE_ITEM VALUES (5, 10, 1);
3.3 Sample SQL Queries
Displays Customer names and credit card numbers/type of credit card on file:
SELECT CUST_FNAME, CUST_LNAME, CUST_CREDIT_NUM, CUST_CREDIT_TYPE
FROM CUSTOMER, CUST_CREDIT_CARD
WHERE CUSTOMER.CUST_ID = CUST_CREDIT_CARD.CUST_ID;
Displays book titles and their corresponding author(s):
SELECT BOOK_TITLE, AUTHOR_FNAME, AUTHOR_LNAME
FROM AUTHOR, BOOK, BOOK_AUTHOR
WHERE AUTHOR.AUTHOR_ID = BOOK_AUTHOR.AUTHOR_ID
AND BOOK.BOOK_ID = BOOK_AUTHOR.BOOK_ID
ORDER BY AUTHOR_LNAME;
Displays orders that have not shipped yet:
SELECT CUST_FNAME,CUST_LNAME, INVOICE.INVOICE_ID, INVOICE_DATE
FROM INVOICE, CUSTOMER, CUST_CREDIT_CARD
WHERE CUST_CREDIT_CARD.CUST_CREDIT_ID = INVOICE.CUST_CREDIT_ID
AND CUSTOMER.CUST_ID = CUST_CREDIT_CARD.CUST_ID
AND INVOICE_SHIP_DATE IS NULL;
Displays credit cards that are expired:
SELECT CUST_FNAME, CUST_LNAME, CUST_CREDIT_NUM, CUST_CREDIT_TYPE,
14
CUST_CREDIT_EXPIRATION
FROM CUSTOMER, CUST_CREDIT_CARD
WHERE CUSTOMER.CUST_ID = CUST_CREDIT_CARD.CUST_ID
AND CUST_CREDIT_EXPIRATION <= CURDATE();
Displays concatenated first and last names of customer as a single attribute (name)
along with each customer’s email address:
SELECT CONCAT(CUST_FNAME," ",CUST_LNAME) AS NAME, CUST_EMAIL_ADDRESS
FROM CUSTOMER
Displays each line item along with book price and total line item price:
SELECT INVOICE_ID, LINE_ITEM.BOOK_ID, LINE_ITEM_QUANT, BOOK_PRICE,
LINE_ITEM_QUANT*BOOK_PRICE AS LINE_ITEM_PRICE
FROM LINE_ITEM, BOOK
WHERE LINE_ITEM.BOOK_ID=BOOK.BOOK_ID
Displays the total price of each invoice:
SELECT INVOICE.INVOICE_ID, INVOICE_DATE, SUM(LINE_ITEM_QUANT*BOOK_PRICE) AS INVOICE_TOTAL
FROM LINE_ITEM, BOOK, INVOICE
WHERE LINE_ITEM.BOOK_ID=BOOK.BOOK_ID
AND INVOICE.INVOICE_ID=LINE_ITEM.INVOICE_ID
GROUP BY INVOICE_ID
4 Summary of Project
This project provided an understanding of the steps that are essential in the
creation of an online bookstore’s database. The data model illustrates the process by
which a database is constructed based on multiple tables and their relationships. The
first step as a database designer is to understand the relationships between the
different data elements and create a logical data structure based upon the
relationships between those elements. The design process began with determining
the purpose of the database, which was to manage an online bookstore’s storefront.
Then the types of information essential to this endeavor were gathered and organized
in a logical manner. The information was then sorted into tables based on the
important entities such as AUTHOR, BOOK, CUSTOMER as well as others. The tables
were populated with attributes, or fields, that were characteristics of the entity
assigned to that table. Tables were assigned primary keys to uniquely identify them.
Relationships were established based on how the data within tables were related to
other tables. The ER diagram was created to show this process in a rational order and
then normalized to ensure that they were correct. The business rules are illustrated
in the design as well as being written out for a better understanding of exactly how
each entity relates to another. A data dictionary was created to compile data
descriptions for the use of the database management system. Through the use of a
DBMS the organization, storage, management and retrieval of all of the data within
the database is possible. Using SQL, along with the parameters set in the data
dictionary, several queries were created to test the functionality of the database
created for the online Book Market store. This project successfully brought together
all of the elements of database design.
15
Download