mysql实验6

实验六 数据库设计

一)实验目的

设计电子商城数据库

(二)实验要求

请大家将执行结果以图片形式完成实验报告,并在最后给出自己经过实验得到的总结。

(三)实验学时

2学时

)实验内容

1. 根据文字提示,完成商品购物流程的数据库设计

2.根据常见购物车功能,设计出购物车表的结构和SQL语句

# 购物车
create table sh_user_shopcart(
id int unsigned primary key auto_increment comment '购物车id',
user_id int unsigned not null default 0 comment '用户id',
goods_id int unsigned not null default 0 comment '商品id',
goods_price decimal(10,2) unsigned not null default 0 comment '单价',
goods_num int unsigned not null default 0 comment '购买件数',
is_select tinyint unsigned not null default 0 comment '是否选中',
create_time datetime default null comment '创建时间',
update_time datetime default null comment '更新时间'
)

3.根据收货地址功能,设计出收货地址表的结构和SQL语句

# 收获地址
create table sh_user_address(
id int unsigned primary key auto_increment comment '地址id',
user_id int unsigned not null default 0 comment '用户id',
is_default tinyint unsigned not null default 0 comment '是否默认',
province varchar(20) not null default '' comment '省',
city varchar(20) not null default '' comment '市',
district varchar(20) not null default '' comment '区',
address varchar(255) not null default '' comment '具体地址',
zip varchar(20) not null default '' comment '邮编',
consignee varchar(20) not null default '' comment '收件人',
phone varchar(20) not null default '' comment '联系电话',
create_time datetime default null comment '创建时间',
update_time datetime default null comment '更新时间'
)

4. 根据订单功能,设计出订单和订单商品表的结构和SQL语句

# 订单
create table sh_order(
id int unsigned primary key auto_increment comment '订单id',
user_id int unsigned not null default 0 comment '用户id',
total_price decimal(10,2) unsigned not null default 0 comment '订单总价',
order_price decimal(10,2) unsigned not null default 0 comment '应付金额',
province varchar(20) not null default '' comment '省',
city varchar(20) not null default '' comment '市',
district varchar(20) not null default '' comment '区',
address varchar(255) not null default '' comment '具体地址',
zip varchar(20) not null default '' comment '邮编',
consignee varchar(20) not null default '' comment '收件人',
phone varchar(20) not null default '' comment '联系电话',
is_valid tinyint unsigned not null default 0 comment '是否有效',
is_cancel tinyint unsigned not null default 0 comment '是否取消',
is_pay tinyint unsigned not null default 0 comment '是否付款',
status tinyint unsigned not null default 0 comment '物流状态',
is_del tinyint unsigned not null default 0 comment '是否删除',
create_time datetime default null comment '创建时间',
update_time datetime default null comment '更新时间'
)
# 订单商品表
create table sh_order_goods(
id int unsigned primary key auto_increment comment 'id',
order_id int unsigned not null default 0 comment '订单id',
goods_id int unsigned not null default 0 comment '商品id',
goods_name varchar(120) not null default '' comment '商品名称',
goods_num int unsigned not null default 0 comment '购买数量',
goods_price  decimal(10,2) unsigned not null default 0 comment '商品单价',
user_note varchar(255) not null default '' comment '用户备注',
staff_name varchar(255) not null default '' comment '卖家备注'
)

5.根据常见的评分功能 ,设计出商品评分表的结构和SQL语句

# 商品评分
create table sh_goods_score(
id int unsigned primary key auto_increment comment '评分id',
user_id int unsigned not null default 0 comment '用户id',
goods_id int unsigned not null default 0 comment '商品id',
goods_score tinyint unsigned not null default 0 comment '商品评分',
service_score tinyint unsigned not null default 0 comment '服务评分',
express_score tinyint unsigned not null default 0 comment '物流评分',
is_invalid tinyint unsigned not null default 0 comment '是否无效',
create_time datetime default null comment '评分时间'
)

 注意:若读者根据书上习题内容在创建表的过程中出现了Invalid default value for 'create_time'错误,究其原因,其实是因为Mysql的版本不同,如果版本为5.5及5.5以下,就会出现此错误,解决方法如下:

将 

create_time datetime default current_timestamp comment '创建时间' 

修改为

create_time datetime default null comment '创建时间'

即可

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值