用mysql设计一个订单表
时间: 2024-06-02 22:14:22 浏览: 23
CREATE TABLE orders (
order_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
total_amount DECIMAL(10,2) NOT NULL,
shipping_address VARCHAR(255) NOT NULL,
payment_method VARCHAR(50) NOT NULL,
payment_status ENUM('pending', 'paid', 'failed') NOT NULL DEFAULT 'pending',
shipping_status ENUM('pending', 'shipped', 'delivered') NOT NULL DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
该订单表包含以下字段:
- 订单ID(order_id):用于唯一标识每个订单,自动递增
- 客户ID(customer_id):与客户表中的ID相关联,不能为空
- 订单日期(order_date):订单创建日期,不能为空
- 订单总金额(total_amount):订单的总金额,不能为空
- 配送地址(shipping_address):订单的配送地址,不能为空
- 支付方式(payment_method):订单的支付方式,不能为空
- 支付状态(payment_status):订单的支付状态,可以是“待支付”,“已支付”,“支付失败”
- 配送状态(shipping_status):订单的配送状态,可以是“待发货”,“已发货”,“已送达”
- 创建时间(created_at):订单创建时间,自动生成
- 更新时间(updated_at):订单更新时间,自动生成
其中,客户ID(customer_id)字段是外键,参考了客户表(customers)中的ID字段。
相关推荐
![sql](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)