MySQL数据库创建商品表

(注:若直接复制上去会报错,可能是标点符号问题,所有标点符号均为英文状态!)
1.商品分类表
创建商品分类表(选择mydb数据库)
use mydb;
create table sh_good_category(
id int unsigned primary key auto_increment comment ‘分类id’,
parent_id int unsigned not null default 0 comment’上级分类id’,
name varchar(100) not null default’‘comment’名称’,
sort int not null default 0 comment’排序’,
is_show tinyint unsigned not null default 0 comment’是否显示’,
create_time datetime not null default current_timestamp comment’创建时间’,
update_time datetime default null comment’更新时间’
);
(注:MySQL5.7以下的版本会出现1067错误,此时应将create_time datetime not null default current_timestamp comment’创建时间’, 改为create_time timestamp not null default current_timestamp comment’创建时间’, 即可。)
添加测试数据
insert into sh_goods_category(id,parent_id,name)values
(1,0,‘办公’),(2,1,‘耗材’),(3,2,‘文具’),(4,0,‘电子产品’),
(5,4,‘通讯’),(6,5,‘手机’),(7,4,‘影音’),(8,7,‘音箱’),
(9,7,‘耳机’),(10,4,‘电脑’),(11,10,‘台式电脑’),(12,10,‘笔记本’),
(13,0,‘服装’),(14,13,‘女装’),(15,14,‘风衣’),(16,14,‘毛衣’);
查看select *from sh_goods_category;
2.商品表
创建商品表(选择mydb数据库)
use mydb;
create table sh_goods(
id int unsigned primary key auto_increment comment’商品id’,
category_id int unsigned not null default 0 comment’分类id’,
spu_id int unsigned not null default 0 comment’SPU id’,
sn varchar(20) not null default ‘’ comment’编号’,
name varchar(120) not null default ‘‘comment’名称’,
keyword varchar(255)not null default ‘’ comment’关键字’,
picture varchar(255) not null default’’ comment’图片’,
tips varchar(255) not null default ‘’ comment’提示’,
description varchar(255) not null default ‘’ comment’描述’,
content text not null comment’详情’,
price decimal(10,2)unsigned not null default 0 comment ‘价格’,
stock int unsigned not null default 0 comment ‘库存’,
score decimal (3,2) unsigned not null default 0 comment’评分’,
is_on_sale tinyint unsigned not null default 0 comment’是否上架’,
is_del tinyint unsigned not null default 0 comment’是否删除’,
is_free_shipping tinyint unsigned not null default 0 comment’是否包邮’,
sell_count int unsigned not null default 0 comment’销量计数’,
comment int unsigned not null default 0 comment’评论计数’,
on_sale_time datetime default null comment’上架时间’,
create_time datetime not null default current_timestamp comment’创建时间’,
update_time datetime default null comment’更新时间’
);
(若出现1067错误,改法同上)
插入测试数据
insert into sh_goods(id,category_id,name,keyword,content,price,stock,score,comment)values
(1,3,‘2B铅笔’,‘文具’,‘考试专用’,0.5,500,4.9,40000),
(2,3,‘钢笔’,‘文具’,‘练字必不可少’,15,300,3.9,500),
(3,3,‘碳素笔’,‘文具’,‘平时使用’,1,500,5,98000),
(4,12,‘超薄笔记本’,‘电子产品’,‘轻小便携’,5999,0,2.5,200),
(5,6,‘智能手机’,‘电子产品’,‘人人必备’,1999,0,5,98000),
(6,8,‘桌面音箱’,‘电子产品’,‘扩音装备’,69,750,4.5,1000),
(7,9,‘头戴耳机’,‘电子产品’,‘独享个人世界’,109,0,3.9,500),
(8,10,‘办公电脑’,‘电子产品’,‘适合办公’,2000,0,4.8,6000),
(9,15,‘收腰风衣’,‘服装’,‘春节潮流单品’,299,0,4.9,40000),
(10,16,‘薄毛衣’,‘服装’,‘居家旅行必备’,48,0,4.8,98000);
查看select *from sh_goods;

发布了30 篇原创文章 · 获赞 32 · 访问量 976

猜你喜欢

转载自blog.csdn.net/cleverlemon/article/details/102565006
今日推荐