以上方代码为基础再加五个不同的表并将这十个表中插入数据
时间: 2024-11-27 15:22:37 浏览: 4
计算机应用基础-作业5.pdf
基于之前的五个基础表,我们可以添加以下五个新表:
1. **评价表 (Reviews)**
```sql
CREATE TABLE Reviews (
Review_ID INT AUTO_INCREMENT PRIMARY KEY,
User_ID INT,
Car_ID INT,
Rating INT(1) CHECK (Rating BETWEEN 1 AND 5),
Comment TEXT,
Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (User_ID) REFERENCES Users(ID),
FOREIGN KEY (Car_ID) REFERENCES Cars(ID)
);
```
2. **优惠活动表 (Promotions)**
```sql
CREATE TABLE Promotions (
Promotion_ID INT AUTO_INCREMENT PRIMARY KEY,
Start_Date DATE,
End_Date DATE,
Discount DECIMAL(5, 2) CHECK (Discount > 0 AND Discount <= 1),
Car_Categories VARCHAR(255) ARRAY,
Applied BOOLEAN DEFAULT FALSE
);
```
3. **经销商表 (Dealerships)**
```sql
CREATE TABLE Dealerships (
Dealer_ID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100),
Address VARCHAR(255),
Phone VARCHAR(20),
Website VARCHAR(100)
);
```
4. **售后服务记录表 (AfterSales)**
```sql
CREATE TABLE AfterSales (
Record_ID INT AUTO_INCREMENT PRIMARY KEY,
User_ID INT,
Car_ID INT,
Issue VARCHAR(255),
Resolution TEXT,
Date DATE,
FOREIGN KEY (User_ID) REFERENCES Users(ID),
FOREIGN KEY (Car_ID) REFERENCES Cars(ID)
);
```
5. **购买历史表 (PurchaseHistory)**
```sql
CREATE TABLE PurchaseHistory (
History_ID INT AUTO_INCREMENT PRIMARY KEY,
User_ID INT,
Car_ID INT,
Purchase_Date DATE,
PaymentMethod ENUM('Cash', 'Credit', 'Online') DEFAULT 'Online',
FOREIGN KEY (User_ID) REFERENCES Users(ID),
FOREIGN KEY (Car_ID) REFERENCES Cars(ID)
);
```
对于数据插入,你可以选择一些示例数据填充,例如:
```sql
INSERT INTO Users (Username, Password, Email) VALUES ('JohnDoe', 'Password123', 'john.doe@example.com');
INSERT INTO Cars (Brand, Model, Price, Category_ID) VALUES ('Toyota', 'Camry', 28000, 1);
INSERT INTO Categories (Name, Description) VALUES ('Sedans', 'Family cars for daily commuting');
... (继续添加更多数据到各个表中)
```
记住,在实际应用中,数据应使用安全的方式存储,如对密码进行哈希加密。
阅读全文