建立一个商场商品的数据库
时间: 2023-09-17 19:11:56 浏览: 48
好的,下面是一个简单的商场商品数据库的设计:
1. 商品表(products)
- id:商品唯一标识符(自增整数)
- name:商品名称(字符串)
- description:商品描述(字符串)
- price:商品价格(浮点数)
- category_id:商品所属分类的唯一标识符(整数)
2. 商品分类表(categories)
- id:分类唯一标识符(自增整数)
- name:分类名称(字符串)
3. 商店表(shops)
- id:商店唯一标识符(自增整数)
- name:商店名称(字符串)
- address:商店地址(字符串)
4. 商品商店表(product_shop)
- id:唯一标识符(自增整数)
- product_id:商品唯一标识符(整数)
- shop_id:商店唯一标识符(整数)
其中,商品表和商店表是基础表,商品分类表是一个辅助表,商品商店表是一个关联表。
下面是一个示例SQL代码用于创建上述表:
```
CREATE TABLE products (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
price FLOAT NOT NULL,
category_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (category_id) REFERENCES categories(id)
);
CREATE TABLE categories (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE shops (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE product_shop (
id INT NOT NULL AUTO_INCREMENT,
product_id INT NOT NULL,
shop_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (product_id) REFERENCES products(id),
FOREIGN KEY (shop_id) REFERENCES shops(id)
);
```
这样,你就可以在这个数据库中添加商品、分类、商店和商品商店关系了。希望这可以帮助你入门。如果你有任何问题,请随时问我!
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)