数据库的设计

 

创建 "商品分类" 表(之前已经创建,无需再次创建)

create table goods_cates(
    id int unsigned primary key auto_increment not null, name varchar(40) not null ); 

创建 "商品品牌" 表(之前已经创建,无需再次创建)

create table goods_brands (
    id int unsigned primary key auto_increment not null, name varchar(40) not null ); 

创建 "商品" 表(之前已经创建,无需再次创建)

create table goods(
    id int unsigned primary key auto_increment not null, name varchar(40) default '', price decimal(5,2), cate_id int unsigned, brand_id int unsigned, is_show bit default 1, is_saleoff bit default 0, foreign key(cate_id) references goods_cates(id), foreign key(brand_id) references goods_brands(id) ); 

创建 "顾客" 表

create table customer(
    id int unsigned auto_increment primary key not null, name varchar(30) not null, addr varchar(100), tel varchar(11) not null ); 

创建 "订单" 表

create table orders(
    id int unsigned auto_increment primary key not null, order_date_time datetime not null, customer_id int unsigned, foreign key(customer_id) references customer(id) ); 

创建 "订单详情" 表

create table order_detail(
    id int unsigned auto_increment primary key not null, order_id int unsigned not null, goods_id int unsigned not null, quantity tinyint unsigned not null, foreign key(order_id) references orders(id), foreign key(goods_id) references goods(id) ); 

说明

  • 以上创建表的顺序是有要求的,即如果goods表中的外键约束用的是goods_cates或者是goods_brands,那么就应该先创建这2个表,否则创建goods会失败
  • 创建外键时,一定要注意类型要相同,否则失败

转载于:https://www.cnblogs.com/jyue/p/10493601.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值