用sql写一个网上书店系统数据库课程设计
时间: 2023-12-27 11:01:51 浏览: 65
网上书店系统数据库课程设计
4星 · 用户满意度95%
下面是一个简单的网上书店系统数据库设计,包含以下几个表:
1. 书籍表(books)
- book_id:书籍ID
- book_name:书籍名称
- author:作者
- publisher:出版社
- publish_date:出版日期
- price:价格
- stock:库存量
2. 用户表(users)
- user_id:用户ID
- username:用户名
- password:密码
- email:邮箱
- phone:电话
3. 订单表(orders)
- order_id:订单ID
- user_id:用户ID
- order_date:下单日期
- total_price:总价
4. 订单详情表(order_details)
- order_detail_id:订单详情ID
- order_id:订单ID
- book_id:书籍ID
- quantity:数量
以下是SQL代码:
```
CREATE TABLE books (
book_id INT PRIMARY KEY,
book_name VARCHAR(50),
author VARCHAR(50),
publisher VARCHAR(50),
publish_date DATE,
price DECIMAL(10,2),
stock INT
);
CREATE TABLE users (
user_id INT PRIMARY KEY,
username VARCHAR(50),
password VARCHAR(50),
email VARCHAR(50),
phone VARCHAR(50)
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
user_id INT,
order_date DATE,
total_price DECIMAL(10,2),
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
CREATE TABLE order_details (
order_detail_id INT PRIMARY KEY,
order_id INT,
book_id INT,
quantity INT,
FOREIGN KEY (order_id) REFERENCES orders(order_id),
FOREIGN KEY (book_id) REFERENCES books(book_id)
);
```
阅读全文