使用 CREATE TABLE 语句对关系架构进行编码。请注意,这组语句应指定完整性约束:键、关系等。Book 表: ISBN (主键) Title Edition Date of Publication Price Book Description Author 表: Author_id (主键) Author Name Publisher 表: Publisher id (主键) Publisher Name Address AK: Publisher Name + Address Customer 表: Customer_id (主键) Name Mailing Address Phone Number Email Address AK: Credit Card Number and Expiration Date Shipment 表: Tracking Number (主键) Date of Shipment Date of Expected Delivery Order 表: Order Number (主键) Mailing Address Method of Shipment Date and Time of Order Total Price of the Order Promotion 表: Promotion id number (主键) Percentage Discount Points Duration of Promotion (start date and end date) Line Item 表: Book ISBN (外键指向 Book 表) Order Number (外键指向 Order 表) Total price for each book that is ordered Quantity of each item ordered Category 表: Category ID (主键) Category Name
时间: 2024-04-02 08:34:34 浏览: 65
好的,以下是对关系架构进行编码的 CREATE TABLE 语句,包含了完整性约束:
```
CREATE TABLE Book (
ISBN varchar(13) PRIMARY KEY,
Title varchar(255) NOT NULL,
Edition int NOT NULL,
Date_of_Publication date NOT NULL,
Price decimal(10, 2) NOT NULL,
Book_Description varchar(1000) NOT NULL
);
CREATE TABLE Author (
Author_id int PRIMARY KEY,
Author_Name varchar(255) NOT NULL
);
CREATE TABLE Publisher (
Publisher_id int PRIMARY KEY,
Publisher_Name varchar(255) NOT NULL,
Address varchar(500) NOT NULL,
CONSTRAINT AK_Publisher UNIQUE (Publisher_Name, Address)
);
CREATE TABLE Customer (
Customer_id int PRIMARY KEY,
Name varchar(255) NOT NULL,
Mailing_Address varchar(500) NOT NULL,
Phone_Number varchar(20) NOT NULL,
Email_Address varchar(255) NOT NULL,
CONSTRAINT AK_CreditCard UNIQUE (Credit_Card_Number, Expiration_Date)
);
CREATE TABLE Shipment (
Tracking_Number int PRIMARY KEY,
Date_of_Shipment datetime NOT NULL,
Date_of_Expected_Delivery datetime NOT NULL
);
CREATE TABLE Order (
Order_Number int PRIMARY KEY,
Mailing_Address varchar(500) NOT NULL,
Method_of_Shipment varchar(255) NOT NULL,
Date_and_Time_of_Order datetime NOT NULL,
Total_Price_of_Order decimal(10, 2) NOT NULL,
CONSTRAINT FK_Customer_Order FOREIGN KEY (Customer_id) REFERENCES Customer(Customer_id)
);
CREATE TABLE Promotion (
Promotion_id int PRIMARY KEY,
Percentage_Discount decimal(5, 2) NOT NULL,
Points int NOT NULL,
Start_Date date NOT NULL,
End_Date date NOT NULL
);
CREATE TABLE Line_Item (
Book_ISBN varchar(13) NOT NULL,
Order_Number int NOT NULL,
Total_Price decimal(10, 2) NOT NULL,
Quantity int NOT NULL,
CONSTRAINT PK_Line_Item PRIMARY KEY (Book_ISBN, Order_Number),
CONSTRAINT FK_Book_Line_Item FOREIGN KEY (Book_ISBN) REFERENCES Book(ISBN),
CONSTRAINT FK_Order_Line_Item FOREIGN KEY (Order_Number) REFERENCES Order(Order_Number)
);
CREATE TABLE Category (
Category_ID int PRIMARY KEY,
Category_Name varchar(255) NOT NULL
);
```
阅读全文