--数据库初始化脚本
--创建数据库
CREATEdatabase seckill;
--使用数据库
use seckill;
--创建秒杀库存表
create tableseckill(
`seckill_id`bigintnot NULLauto_increment comment'商品库存id',
`name`varchar(20)not NULLcomment'商品名称',
`num`int NOT NULLcomment'库存数量',
`start_time`TIMESTAMP NOT NULLcomment'秒杀开启时间',
`end_time`TIMESTAMP NOT NULLcomment'秒杀结束时间',
`create_time`TIMESTAMP NOT NULL DEFAULTCURRENT_TIMESTAMPcomment'创建时间'
PRIMARY KEY(seckill_id),
KEYidx_start_time(start_time),
KEYidx_end_time(end_time),
KEYidx_create_time(create_time)
)ENGINE= InnoDB AUTO_INCREMENT=1000DEFAULTCHARSET=utf8 comment='秒杀库存表';
--初始化数据
INSERT INTOseckill (name,num,start_time,end_time)VALUES('1000元秒杀iphone7',100,'2017-01-12 00:00:00','2017-01-13 00:00:00'),
('500元秒杀ipad',100,'2017-01-12 00:00:00','2017-01-13 00:00:00'),
('10000元秒杀macbook',100,'2017-01-12 00:00:00','2017-01-13 00:00:00'),
('100元秒杀applewatch',100,'2017-01-12 00:00:00','2017-01-13 00:00:00');
--秒杀成功明细表
--用户登录认证相关的信息
create tablesuccess_killed(
`seckill_id`bigintnot nullcomment'秒杀商品id',
`user_phone`bigintnot nullcomment'用户手机号',
`state`tinyintnot null DEFAULT-1comment'状态标示:-1:无效 0:成功 1:已付款',
`create_time`TIMESTAMP NOT NULLcomment'创建时间',
PRIMARY KEY(seckill_id,user_phone),/*联合*/
KEYidx_create_time(create_time)
)ENGINE=InnoDBDEFAULTCHAR�SET=utf8 comment='秒杀成功明细表';
--连接mysql数据控制台
mysql -u root -p root
网友评论