market/sql/market-curd.sql

184 lines
9.1 KiB
SQL

-- 员工表
drop table if exists tb_employee;
create table tb_employee(
emp_id int(11) comment '员工Id' primary key auto_increment,
emp_name varchar(55) comment '员工姓名',
username varchar(55) comment '员工用户名',
password varchar(55) comment '员工密码',
emp_tel varchar(20) comment '员工手机号',
emp_id_card varchar(20) comment '员工身份证号',
emp_age int(11) comment '员工年龄',
emp_gender int(11) comment '员工性别:1-男 2-女',
emp_address varchar(20) comment '员工住址',
emp_sal decimal(10,2) comment '员工薪资'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='员工表';
insert into tb_employee (emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal) values ('李四','lisi','lisi','13320560246','320145199702059783',26,1,'北京市大兴区XXX路XX号', 50000);
insert into tb_employee (emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal) values ('王五','wangwu','wangwu','13320456237','32014519970204563X',26,2,'北京市大兴区XXX路XX号',10000);
insert into tb_employee (emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal) values ('赵六','zhaoliu','zhaoliu','13320456282','32014519971204563X',26,2,'北京市大兴区XXX路XX号',10000);
insert into tb_employee (emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal) values ('田七','tianqi','tianqi','13320456291','32014519970224563X',26,1,'北京市大兴区XXX路XX号',10000);
insert into tb_employee (emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal) values ('候八','houba','houba','13320456200','32014519970604563X',26,2,'北京市大兴区XXX路XX号',5000);
insert into tb_employee (emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal) values ('罗九','luojiu','luojiu','13320456263','32014519950604563X',28,1,'北京市大兴区XXX路XX号',5000);
select emp_id, emp_name, username, password, emp_tel, emp_id_card, emp_age, emp_gender, emp_address, emp_sal from tb_employee;
-- 角色表
drop table if exists tb_role;
create table tb_role(
role_id int(11) comment '角色Id' primary key auto_increment,
role_name varchar(55) comment '角色名称'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='角色表';
insert into tb_role (role_name) values ('超级管理员');
insert into tb_role (role_name) values ('仓库管理员');
insert into tb_role (role_name) values ('普通管理员');
insert into tb_role (role_name) values ('销售员');
select role_id, role_name from tb_role;
-- 用户角色中间表
drop table if exists tb_emp_role;
create table tb_emp_role(
emp_role_id int(11) primary key auto_increment,
emp_id int(11) comment '员工',
role_id int(11) comment '角色'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='用户角色表';
insert into tb_emp_role (emp_id, role_id) values (1,1);
insert into tb_emp_role (emp_id, role_id) values (2,2);
insert into tb_emp_role (emp_id, role_id) values (3,3);
insert into tb_emp_role (emp_id, role_id) values (4,3);
insert into tb_emp_role (emp_id, role_id) values (5,4);
insert into tb_emp_role (emp_id, role_id) values (6,4);
select emp_role_id, emp_id, role_id from tb_emp_role;
-- 岗位表
drop table if exists tb_post;
create table tb_post(
post_id int(11) comment '岗位' primary key auto_increment,
post_name varchar(55) comment '岗位名称'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='岗位表';
insert into tb_post (post_name) values ('董事长');
insert into tb_post (post_name) values ('人事');
insert into tb_post (post_name) values ('客户主管');
insert into tb_post (post_name) values ('后勤');
insert into tb_post (post_name) values ('销售');
select post_id, post_name from tb_post;
-- 员工岗位中间表
drop table if exists tb_emp_post;
create table tb_emp_post(
emp_post_id int(11) primary key auto_increment,
emp_id int(11) comment '员工',
post_id int(11) comment '岗位'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='员工岗位中间表';
insert into tb_emp_post (emp_id, post_id) values (1,1);
insert into tb_emp_post (emp_id, post_id) values (2,4);
insert into tb_emp_post (emp_id, post_id) values (3,2);
insert into tb_emp_post (emp_id, post_id) values (4,3);
insert into tb_emp_post (emp_id, post_id) values (5,5);
insert into tb_emp_post (emp_id, post_id) values (6,5);
select emp_post_id, emp_id, post_id from tb_emp_post;
-- 人员分布
select
e.emp_id,
e.emp_name,
r.role_id,
r.role_name,
p.post_id,
p.post_name
from
tb_employee e
left join tb_emp_role er on e.emp_id = er.emp_id
left join tb_role r on er.role_id = r.role_id
left join tb_emp_post ep on e.emp_id = ep.emp_id
left join tb_post p on ep.post_id = p.post_id;
-- 会员表
drop table if exists tb_vip;
create table tb_vip(
vip_id int(11) comment '会员编号' primary key auto_increment,
vip_name varchar(20) comment '会员姓名',
vip_age int(2) comment '会员年龄',
vip_gender int(11) comment '员工性别:1-男 2-女',
vip_tel long comment '会员联系方式',
vip_grade varchar(1) comment '会员等级',
reg_date datetime comment '注册日期'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='会员表';
insert into tb_vip (vip_name, vip_age, vip_gender, vip_tel, vip_grade, reg_date) values ('张三',20,1,'17373105689',3,'2020-1-1 10:00');
select vip_id, vip_name, vip_age, vip_gender, vip_tel, vip_grade, reg_date from tb_vip;
-- 客户表
drop table if exists tb_customer;
create table tb_customer(
customer_id int(11) comment '客户编号' primary key auto_increment,
customer_name varchar(20) comment '客户姓名',
customer_age varchar(20) comment '客户年龄',
customer_gender int(11) comment '客户性别:1-男 2-女',
customer_address varchar(20) comment '客户住址',
customer_tel varchar(20) comment '客户联系方式'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='客户表';
insert into tb_customer (customer_name, customer_age, customer_gender, customer_address, customer_tel) values ('张三',20,1,'北京市大兴区XXX路XX号','17373105689');
select customer_id, customer_name, customer_age, customer_gender, customer_address, customer_tel from tb_customer;
-- 商品表
drop table if exists tb_merch;
create table tb_merch(
merch_id int(11) comment '商品编号' primary key auto_increment,
merch_name varchar(20) comment '商品名称',
merch_type varchar(10) comment '商品类型',
merch_price decimal(4,2) comment '价格',
bar_code varchar(20) comment '条形码',
sales_pro_price decimal(4,2) comment '促销价',
factory_id varchar(10) comment '厂商编号',
provide_id varchar(10) comment '供货商编号',
merch_dead_time datetime comment '过期日期',
merch_num int(4) comment '库存数量',
merch_sta int(10) default 2 comment '商品状态:1-未上架 2-上架 3-下架'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='商品表';
insert into tb_merch (merch_name, merch_type, merch_price, bar_code, sales_pro_price, factory_id, provide_id, merch_dead_time, merch_num)
values ('青芒','生鲜水果',30,'asfdghj',20,'001','0011','2023-11-30',500);
select merch_id, merch_name, merch_type, merch_price, bar_code, sales_pro_price, factory_id, provide_id, merch_dead_time, merch_num, merch_sta from tb_merch;
-- 进货表
drop table if exists tb_import;
create table tb_import(
list_id int(11) comment '表单编号' primary key auto_increment,
merch_id int(11) comment '商品编号',
merch_name varchar(20) comment '商品名称',
merch_type varchar(10) comment '商品类型',
merch_price decimal(4,2) comment '价格',
plan_num int(4) comment '计划进货数',
import_date date comment '进货日期',
provide_id varchar(10) comment '供货商编号'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='进货表';
-- 销售表
drop table if exists tb_sale_list;
create table tb_sale_list(
list_id int(11) comment '表单编号' primary key auto_increment,
merch_id int(11) comment '商品Id',
merch_name varchar(55) comment '商品名称',
sales_price decimal(10,2) comment '',
bar_code varchar(20) comment '条形码',
merch_type int(11) comment '商品类型'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='销售表';
-- 退货表
drop table if exists tb_withdraw_list;
create table tb_withdraw_list(
list_id int(11) comment '表单编号' primary key auto_increment,
merch_id int(11) comment '商品Id',
merch_name varchar(55) comment '商品名称',
bar_code varchar(20) comment '条形码',
withdraw_num int(11) comment '退货数量'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='退货表';
-- 上报进货表
drop table if exists tb_report_impl_list;
create table tb_report_impl_list(
list_id int(11) comment '表单编号' primary key auto_increment,
merch_id int(11) comment '商品Id',
merch_name varchar(55) comment '商品名称'
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='退货表';