mysql电商建库脚本

create database if not exists jspshopping;
use jspshopping;
/*1商品表*/
create TABLE commodity(
commodityID varchar(50) not null PRIMARY KEY comment '商品编号',
commodityName varchar(50) not null comment '商品名称',
commodityTypeID varchar(50) not null comment '商品类型',
commodityBrandID varchar(50) not null comment '商品品牌',
placeOfOrigin varchar(50) comment '商品产地',
textureOfMaterial varchar(100) comment '商品材质',
isOnline bit not null DEFAULT 0 comment '商品是否上线,默认为没上线', /*默认为没上线*/
describeA varchar(100) not null comment '商品备注描述'
);
/*2品牌表*/
create Table brand(
brandID varchar(50) not null PRIMARY KEY comment '品牌编号',
brandName varchar(50) not null comment '品牌名字',
brandGrade int comment '品牌等级'
);
/*3商品类型表*/
create TABLE category(
categoryID varchar(50) not null PRIMARY KEY comment '类型编号',
categoryName varchar(50) comment '类型名称'
);
alter table commodity add CONSTRAINT SP_Type FOREIGN KEY (commodityTypeID) REFERENCES category(categoryID);/*商品表与类型表建立外键*/
alter table commodity add CONSTRAINT SP_Brand FOREIGN KEY (commodityBrandID) REFERENCES brand(brandID);/*商品表与品牌表建立外键*/
/*4库存表*/
CREATE TABLE stock(
stockID varchar(50) not null PRIMARY KEY comment '库存编号',
commodityID varchar(50) not null comment '商品编号',
color varchar(50) not null comment '商品颜色',
thePurchasePrice DECIMAL(8,2) not null comment '商品进价',
commodityNumber int not null comment '商品总数量',
sellOutNumber int not null comment '商品卖出数量',
surplusNumber int not null comment '商品剩余数量'
);
/*5图片收入表*/
CREATE TABLE image(
stockID varchar(50) not null comment '库存编号',
commodityID varchar(50) not null comment '商品编号',
imageName varchar(50) not null comment '图片存放路径或图片名称',
imageType int not null DEFAULT 0 comment '图片类型,默认为基础图片类型,1为主图片,2为广告图片'
);
/*6商品上线表*/
CREATE TABLE GoOnline(
commodityID varchar(50) not null comment '商品编号',
isOnline bit not null DEFAULT 0 comment '商品是否在线,默认为在线',
CommodityName varchar(50) not null comment '商品名称',
brandID varchar(50) not null comment '商品品牌编号',
categoryID varchar(50) not null comment '商品类型编号',
isAdvertisement int not null DEFAULT 0 comment '是否为广告商品,默认不为广告商品',
price DECIMAL(8,2) not null comment '商品售价'
);
/*7商品上下线记录表*/
create table GoOrOutonline(
commodityID varchar(50) not null comment '商品编号',
goOnlineTime TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP comment'上下线时间为默认插入数据时间',
onlineA int not null comment '上下线标明,0为上线,1为下线',
onlinePrice DECIMAL(8,2) comment '上线价格,下线可不必填'
);
/*8商品动态表*/
create table dynamic(
commodityID varchar(50) not null comment '商品编号',
number int comment '商品增加数量,不是增加记录则为空',
thepurchasePrice DECIMAL(8,2) comment '商品进价修改,同上',
price DECIMAL(8,2) comment '商品售价修改,同上',
color varchar(50) comment '商品颜色,如增加某个颜色商品数量时可填写,不填即增加代表该商品只有一种颜色',
time TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP comment'修改时间为默认插入数据时间'
);
alter table stock add CONSTRAINT KCun_Com FOREIGN KEY (commodityID) REFERENCES commodity(commodityID);/*库存表与商品表建立外键*/
alter table image add CONSTRAINT im_sto FOREIGN KEY (stockID) REFERENCES stock(stockID);/*图片表与库存表建立外键*/
alter table GoOnline add CONSTRAINT on_com FOREIGN KEY (commodityID) REFERENCES commodity(commodityID);/*商品上线表与商品表建立外键*/
alter table GoOrOutonline add CONSTRAINT or_com FOREIGN KEY (commodityID) REFERENCES commodity(commodityID);/*商品上下线记录表与商品表建立外键*/
alter table dynamic add CONSTRAINT dy_com FOREIGN KEY (commodityID) REFERENCES commodity(commodityID);/*商品动态表与商品表建立外键*/
/*9会员表*/
create table Member(
vipPhone varchar(11) not null PRIMARY KEY comment '会员手机号',
vipName varchar(20) not null comment '会员用户名',
vipPwd varchar(18) not null comment '会员密码',
vipIntegral int not null DEFAULT 0 comment '会员消费积分,默认为0分',
vipState bit not null DEFAULT 0 comment '会员状态,默认为正常'
);
/*10会员收货地址信息表*/
create table address(
addressID varchar(50) not null PRIMARY KEY comment '收货地址编号',
vipPhone varchar(11) not null comment '会员手机号码',
consigneeName varchar(20) not null comment '收货人姓名',
consigneePhone varchar(11) not null comment '收货人电话',
consigneeDel varchar(100) not null comment '收货人地址',
isDefault bit not null DEFAULT 0 comment '是否设为默认地址,默认为不设为',
addressType int comment '地址类型,0代表工作地址,1代表家庭住址,2代表其它地址'
);
/*11订单表*/
create table orderA(
orderID varchar(50) not null PRIMARY KEY comment '订单编号',
vipPhone varchar(11) not null comment '会员电话',
addressID varchar(50) not null comment '收货地址编号',
number int not null comment '商品数量',
total DECIMAL(16,2) not null comment '订单总价',
isDeliverGoods bit not null DEFAULT 0 comment'该订单是否已发货,默认为未发货',
isCancel bit not null DEFAULT 0 comment '该订单是否已取消,默认为未取消',
orderTime TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP comment '订单产生时间,为默认插入数据时间'
);
/*12订单详情表*/
create table orderDetails(
orderID varchar(50) not null comment '订单编号',
commodityID varchar(50) not null comment '库存编号',
commodityNumber int not null comment '商品数量',
commodityPrice DECIMAL(8,2) not null comment '商品单价',
commodityTotal DECIMAL(16,2) not null comment '商品总价'
);
/*13评论记录表*/
create table commentA(
commentID varchar(50) not null PRIMARY KEY comment '评论ID',
commodityID varchar(50) not null comment '商品编号',
vipPhone varchar(11) not null comment '会员电话',
vipName varchar(20) not null comment '会员用户名',
commentStrig varchar(100) not null comment '商品评论',
reply varchar(100) comment '商家回复,只能商家回复',
commentStrigTime TIMESTAMP not null comment'评论时间',
replyTime TIMESTAMP comment '回复时间'
);
/*14浏览足迹记录表*/
create table footprint(
footprintID varchar(50) not null PRIMARY KEY comment '浏览足迹编号',
vipPhone varchar(11) not null comment '会员电话',
commodityID varchar(50) not null comment '商品编号',
commodityImage varchar(50) not null comment '商品主图片路径或名称',
commodityPrice DECIMAL(8,2) not null comment '商品单价',
commodityName varchar(50) not null comment '商品名字'
);
alter table address add CONSTRAINT add_vip FOREIGN KEY (vipPhone) REFERENCES Member(vipPhone);/*收货地址表与会员表建立外键*/
alter table orderA add CONSTRAINT ord_add FOREIGN KEY (addressID) REFERENCES address(addressID);/*订单表与收货地址编号建立外键*/
alter table orderDetails add CONSTRAINT det_ord FOREIGN KEY (orderID) REFERENCES orderA(orderID);/*订单详情表与订单表建立外键*/
alter table orderDetails add CONSTRAINT det_sto FOREIGN KEY (commodityID) REFERENCES stock(stockID);/*订单详情表与库存表建立外键*/
alter table commentA add CONSTRAINT comA_com FOREIGN KEY (commodityID) REFERENCES commodity(commodityID);/*评论表与商品表建立外键*/
alter table commentA add CONSTRAINT comA_vip FOREIGN KEY (vipPhone) REFERENCES Member(vipPhone);/*评论表与会员表建立外键*/
alter table footprint add CONSTRAINT foot_com FOREIGN KEY (commodityID) REFERENCES commodity(commodityID);/*浏览足迹表与商品表建立外键*/
alter table footprint add CONSTRAINT foot_vip FOREIGN KEY (vipPhone) REFERENCES Member(vipPhone);/*浏览足迹表与会员表建立外键*/
/*15员工表*/
create table Employee(
employeeID varchar(50) not null PRIMARY KEY comment '员工编号',
Birthday date not null comment '出生年月',
sex varchar(1) not null comment '性别',
telePhone varchar(11) not null comment '电话号码',
idCard varchar(18) not null comment '身份证号码',
myPhoto varchar(50) not null comment '本人照片',
presentAddress varchar(100) not null comment '现居地址',
emergencyPerson varchar(20) not null comment '紧急联系人',
emergencyPhone varchar(11) not null comment '紧急联系电话',
employeeState bit not null DEFAULT 0 comment '员工状态,默认为正常'
);
/*16权限详情表*/
create table Jurisdiction(
jurisdictionID varchar(50) not null PRIMARY KEY comment '权限详情编号',
jurisdictionName varchar(20) not null comment '权限名',
jurisdictionDescribe varchar(100) comment '权限功能描述',
jurisdictionState bit not null DEFAULT 0 comment '权限状态,默认为正常'
);
/*17账号表*/
create table accountNumber(
accountNumberID varchar(50) not null PRIMARY KEY comment '账号ID',
accountNumberPwd varchar(18) not null comment '账号密码',
accountNumberEmID varchar(50) not null comment '账号对应的员工编号',
accountNumberState bit not null DEFAULT 0 comment '账号使用状态,默认为正常'
);
/*18权限使用表*/
create table distribution(
employeeID varchar(50) not null comment '员工编号',
jurisdictionID varchar(50) not null comment '权限编号',
distributionState bit not null DEFAULT 0 comment '使用状态,默认为正常使用'
);
alter table accountNumber add CONSTRAINT acc_emp FOREIGN KEY (accountNumberEmID) REFERENCES Employee(employeeID);/*账号表与员工表建立外键*/
alter table distribution add CONSTRAINT dis_emp FOREIGN KEY (employeeID) REFERENCES Employee(employeeID);/*权限使用表与员工表建立外键*/
alter table distribution add CONSTRAINT dis_jur FOREIGN KEY (jurisdictionID) REFERENCES jurisdiction(jurisdictionID);/*权限使用表与权限详情表建立外键*/
posted @ 2017-12-26 10:20  爱写bug的阿亮  阅读(357)  评论(0)    收藏  举报