//Customers can request notification about new books by an author
CREATE TABLE AlertTo (
CustEmailAddress CHAR[120],
DateOfAlertRequest DATE NOT NULL,
AuthorName CHAR[120],
AuthorBirthDate DATE,
PRIMARY KEY (UserEmailAddr, AuthorName, AuthorBirthDate),
FOREIGN KEY (AuthorName, AuthorBirthDate) REFERENCES Author
ON DELETE CASCADE, ON UPDATE CASCADE,
FOREIGN KEY (CustEmailAddr) REFERENCES Customer
ON DELETE NO ACTION, ON UPDATE CASCADE
)
CREATE TABLE Account (/* Customers can have zero or more accounts
CustEmailAddr CHAR[120],
CreditCardNumber INTEGER,
ShippingAddr ADDRESS NOT NULL,
DateOpened DATE NOT NULL,
PRIMARY KEY (CustEmailAddr, CreditCardNumber),
FOREIGN KEY (CustEmailAddr) REFERENCES Customer
ON DELETE CASCADE, ON UPDATE CASCADE
)
// insure participation constraint of Customer in /Accounts – every customer have at least
// one account
CREATE ASSERTION CustomerAccountConstraint
CHECK (NOT EXISTS (SELECT *
FROM Customer C
WHERE C.CustEmailAddr
NOT IN (SELECT A.CustEmailAddr FROM Account A)))
Tables about Purchases and Shipments
//Transaction (purchases) are made on a customer account
CREATE TABLE Transaction (
TransNumber INTEGER,
OrderDate DATE,
PaymentClearanceDate DATE, /* if NULL, then payment has not cleared */
CustEmailAddr CHAR[120] NOT NULL,
CreditCardNo INTEGER NOT NULL,
PRIMARY KEY (TransNum),
FOREIGN KEY (CustEmailAddr, CreditCardNo) REFERENCES Account
ON DELETE NO ACTION, ON UPDATE CASCADE
)