用mysql设计一个商城管理系统,至少有十个表,给出具体代码
时间: 2024-02-23 14:59:42 浏览: 56
商城项目数据库表设计
好的,以下是一个简单的商城管理系统的表结构设计的 MySQL 代码:
```mysql
-- 用户表
CREATE TABLE `user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(50) NOT NULL,
`phone` varchar(20) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 商品表
CREATE TABLE `product` (
`product_id` int(11) NOT NULL AUTO_INCREMENT,
`product_name` varchar(50) NOT NULL,
`product_description` varchar(255) NOT NULL,
`product_price` decimal(10,2) NOT NULL,
`product_stock` int(11) NOT NULL,
PRIMARY KEY (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 订单表
CREATE TABLE `order` (
`order_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`order_status` tinyint(4) NOT NULL,
`order_total_amount` decimal(10,2) NOT NULL,
`order_time` datetime NOT NULL,
PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 订单详情表
CREATE TABLE `order_detail` (
`order_detail_id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`buy_amount` int(11) NOT NULL,
`product_price` decimal(10,2) NOT NULL,
PRIMARY KEY (`order_detail_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 收货地址表
CREATE TABLE `address` (
`address_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`consignee_name` varchar(20) NOT NULL,
`consignee_phone` varchar(20) NOT NULL,
`address_detail` varchar(255) NOT NULL,
PRIMARY KEY (`address_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 购物车表
CREATE TABLE `cart` (
`cart_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`buy_amount` int(11) NOT NULL,
PRIMARY KEY (`cart_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 商品分类表
CREATE TABLE `category` (
`category_id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(20) NOT NULL,
`parent_category_id` int(11) NOT NULL,
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 商品评价表
CREATE TABLE `comment` (
`comment_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`comment_content` varchar(255) NOT NULL,
`comment_time` datetime NOT NULL,
PRIMARY KEY (`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 物流表
CREATE TABLE `logistics` (
`logistics_id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`logistics_status` tinyint(4) NOT NULL,
`consignee_name` varchar(20) NOT NULL,
`consignee_phone` varchar(20) NOT NULL,
`address_detail` varchar(255) NOT NULL,
PRIMARY KEY (`logistics_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 品牌表
CREATE TABLE `brand` (
`brand_id` int(11) NOT NULL AUTO_INCREMENT,
`brand_name` varchar(20) NOT NULL,
`brand_description` varchar(255) NOT NULL,
`brand_logo` varchar(255) NOT NULL,
PRIMARY KEY (`brand_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```
以上是用 MySQL 设计一个简单的商城管理系统的表结构,每个表都有其独特的字段,可以根据实际需求进行修改和优化。
阅读全文