1. Book(Title,ISBN,Edition,Date of Publication,Price,Book Description,Publisher id); PK(ISBN) FK(Publisher id)->Publisher(Publisher id) 2. Author(Author Name,Author_id); PK(Author_id) 3. Publisher(Publisher id,Publisher Name,Address); PK(Publisher id) AK(publisher name,address) 4. Customer(Customer_id,first name,middle name,last name,Mailing Address,Credit Card Number and Expiration Date,Phone Number,Email Address); PK(Customer_id) AK(Credit Card Number and Expiration Date) 5. Shipment(Date of Shipment,Tracking Number,Date of Expected Delivery); PK(Tracking Number) 6. Order(Order Number,Mailing Address,Method of Shipment,Date and Time of Order); PK(Order Number,Customer_id) FK(Customer_id)->Customer(Customer_id) 7. Promotion(Promotion id number,Percentage Discount Points,start date,end date); PK(Promotion id number) 8. Line Item(Total price for each book that is ordered ,Quantity of each item ordered ,Book IBSN,Order Number); FK(Book IBSN)->Book(IBSN);(Order Number)->Order(Order Number);(Tracking Number)->Shipment(Tracking Number) 9. Category(Category ID,Category Name); PK(Category ID) FK(Category ID)->Isa_Category(SubcategoryID) 10. Total Price of the Order(Price,Order Number); FK(Order Number)->Order(Order Number) PK(Price,Order Number) 11. Isa_Category(SubcategoryID,SuperCategoryID); PK(SuperCategoryID) 12. Write(Author_id,ISBN); PK(Author_id,ISBN) FK(Author_id)->Author(Author_ID);(ISBN)->Book(ISBN) 13. BelongTo(ISBN,Category ID); PK(ISBN,Category ID) FK(ISBN)->Book(ISBN);(Category ID)->Category(Category ID) 14. Promote(ISBN,Promotion id number); PK(ISBN,Promotion id number) FK(ISBN)->Book(ISBN);(Promotion id number)->Promotion(Promotion id number)。使用CREATE TABLE语句对关系架构进行编码,应指定完整性约束,键关系等
时间: 2024-04-02 10:33:20 浏览: 81
yearbook of statistics singapore 2019.pdf
下面是关系架构的 CREATE TABLE 代码:
```
CREATE TABLE Book (
Title VARCHAR(255),
ISBN VARCHAR(13) PRIMARY KEY,
Edition INT,
Date_of_Publication DATE,
Price DECIMAL(10,2),
Book_Description TEXT,
Publisher_id INT,
CONSTRAINT fk_publisher_id FOREIGN KEY (Publisher_id) REFERENCES Publisher(Publisher_id)
);
CREATE TABLE Author (
Author_Name VARCHAR(255),
Author_id INT PRIMARY KEY
);
CREATE TABLE Publisher (
Publisher_id INT PRIMARY KEY,
Publisher_Name VARCHAR(255),
Address VARCHAR(255),
CONSTRAINT uk_publisher_name_address UNIQUE (Publisher_Name, Address)
);
CREATE TABLE Customer (
Customer_id INT PRIMARY KEY,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Mailing_Address VARCHAR(255),
Credit_Card_Number VARCHAR(16),
Expiration_Date DATE,
Phone_Number VARCHAR(20),
Email_Address VARCHAR(255),
CONSTRAINT uk_credit_card UNIQUE (Credit_Card_Number, Expiration_Date)
);
CREATE TABLE Shipment (
Date_of_Shipment DATE,
Tracking_Number VARCHAR(255) PRIMARY KEY,
Date_of_Expected_Delivery DATE
);
CREATE TABLE Order (
Order_Number INT PRIMARY KEY,
Mailing_Address VARCHAR(255),
Method_of_Shipment VARCHAR(255),
Date_and_Time_of_Order DATETIME,
Customer_id INT,
CONSTRAINT fk_customer_id FOREIGN KEY (Customer_id) REFERENCES Customer(Customer_id)
);
CREATE TABLE Promotion (
Promotion_id_Number INT PRIMARY KEY,
Percentage_Discount POINT,
Start_Date DATE,
End_Date DATE
);
CREATE TABLE Line_Item (
Total_Price DECIMAL(10,2),
Quantity INT,
Book_ISBN VARCHAR(13),
Order_Number INT,
Tracking_Number VARCHAR(255),
CONSTRAINT fk_book_ISBN FOREIGN KEY (Book_ISBN) REFERENCES Book(ISBN),
CONSTRAINT fk_order_number FOREIGN KEY (Order_Number) REFERENCES Order(Order_Number),
CONSTRAINT fk_tracking_number FOREIGN KEY (Tracking_Number) REFERENCES Shipment(Tracking_Number)
);
CREATE TABLE Category (
Category_ID INT PRIMARY KEY,
Category_Name VARCHAR(255)
);
CREATE TABLE Isa_Category (
SubcategoryID INT PRIMARY KEY,
SuperCategoryID INT,
CONSTRAINT fk_super_category_id FOREIGN KEY (SuperCategoryID) REFERENCES Category(Category_ID)
);
CREATE TABLE Write (
Author_id INT,
ISBN VARCHAR(13),
CONSTRAINT pk_write PRIMARY KEY (Author_id, ISBN),
CONSTRAINT fk_author_id FOREIGN KEY (Author_id) REFERENCES Author(Author_id),
CONSTRAINT fk_isbn FOREIGN KEY (ISBN) REFERENCES Book(ISBN)
);
CREATE TABLE BelongTo (
ISBN VARCHAR(13),
Category_ID INT,
CONSTRAINT pk_belongto PRIMARY KEY (ISBN, Category_ID),
CONSTRAINT fk_belongs_to_isbn FOREIGN KEY (ISBN) REFERENCES Book(ISBN),
CONSTRAINT fk_belongs_to_category_id FOREIGN KEY (Category_ID) REFERENCES Category(Category_ID)
);
CREATE TABLE Promote (
ISBN VARCHAR(13),
Promotion_id_Number INT,
CONSTRAINT pk_promote PRIMARY KEY (ISBN, Promotion_id_Number),
CONSTRAINT fk_promote_isbn FOREIGN KEY (ISBN) REFERENCES Book(ISBN),
CONSTRAINT fk_promote_promotion_id FOREIGN KEY (Promotion_id_Number) REFERENCES Promotion(Promotion_id_Number)
);
CREATE TABLE Total_Price_Of_Order (
Price DECIMAL(10,2),
Order_Number INT,
CONSTRAINT pk_total_price_of_order PRIMARY KEY (Price, Order_Number),
CONSTRAINT fk_total_price_of_order_order_number FOREIGN KEY (Order_Number) REFERENCES Order(Order_Number)
);
```
在 CREATE TABLE 语句中,我为每个表定义了列,以及它们的数据类型和约束。对于每个表,我还定义了一个主键,以便可以唯一标识其中的每一行。我还使用了外键约束,以确保表之间的关系得到维护,并且不会出现无法识别的关系。
阅读全文