Java项目专栏之数据库建表
Java项目专栏之数据库建表
数据库建表前期准备
1. 安装mysql:数据库语言,语法和sql server差不太多,如果习惯于sql server可以不用mysql。
2. 安装navicat:可视化数据库工具,简化你的建表操作。
正式建表
1. 数据库的配置我就不一一讲解了,直接开始建表吧,建表先建主外键约束少或者没有的表。
2. 创建数据库,命名为:shop_manage_system.这里要注意的是,在团队开发过程中,团队成员数据库的字符编码要一样,否则整合会出大问题。
3. 创建供应商表(tb_supply)
* `CREATE TABLE tb_supply (
sup_id INTEGER not null PRIMARY KEY auto_increment, -- 供应商编号,自增
sup_name VARCHAR(20) not null, -- 供应商名称
sup_address VARCHAR(20), -- 供应商地址
sup_linkMan VARCHAR(20), -- 供应商联系人
sup_phone VARCHAR(11), -- 供应商联系电话
sup_status tinyint not null, -- 合作状态(0:保持合作1:解除合作)
sup_mark varchar(50)-- 备注
);`
4. 创建职务信息表(tb_position)
* `create table tb_position(
posi_id Integer not null PRIMARY KEY auto_increment, -- 职务编号,主键 (1:采购员 2:销售员 3:仓库管理员 4:管理员)
posi_name Varchar(20) not null, -- 职务名称
posi_introduction Varchar(50) -- 职务简介
);`
5. 创建员工表(tb_employee)
* `CREATE table tb_employee(
emp_id Integer not null PRIMARY KEY auto_increment, -- 员工编号
emp_password varchar(20) not null, -- 账号密码
emp_name Varchar(20) not null, -- 员工姓名
emp_sex tinyInt not null, -- 员工性别(0:女 1:男)
emp_position_id Integer not null, -- 员工职务编号,外键
emp_phone Varchar(11) not null, -- 员工联系电话
emp_birthday Date , -- 员工出生日期
emp_salary INTEGER not null, -- 员工工资
emp_status tinyInt not null, -- 状态(1:在职 0:开除)
emp_mark Varchar(50), -- 备注
constraint fk_type_position foreign key (emp_position_id) references tb_position(posi_id) -- 职位编号是员工表的外键
);`
6. 创建仓库表(tb_storage)
* `create table tb_storage(
sto_id Integer not null PRIMARY KEY auto_increment, -- 主键,仓库编号
sto_name varchar(20) not null, -- 仓库名称
sto_empId INTEGER not null, -- 员工编号,外键
sto_address varchar(20) , -- 仓库地址
sto_mark varchar(50) , -- 备注
constraint fk_type_employee foreign key (sto_empId) references tb_employee(emp_id) -- 员工编号是仓库表的外键
;`
7. 创建商品表(tb_good)
* `create table tb_good(
goods_id Integer not null PRIMARY KEY auto_increment, -- 主键,商品编号
goods_name varchar(20) not null, -- 商品名称
goods_units varchar(20) , -- 商品单位
goods_size varchar(10) , -- 商品规格大小
goods_purPrice double not null, -- 商品进价
goods_sellPrice double not null, -- 商品售价
goods_number INTEGER not null, -- 商品数量
goods_stoId INTEGER not null, -- 外键,仓库编号
goods_keepDays INTEGER not null, -- 商品保质期
goods_minNumber INTEGER not null, -- 最低库存
goods_mark varchar(50), -- 备注
constraint fk_type_storage foreign key (goods_stoId) references tb_storage(sto_id) -- 仓库编号是商品表的外键
);
alter table tb_good auto_increment = 10001; -- 设置商品表的商品编号从10001开始递增`
8. 创建采购订单表(tb_purchaseOrder)
* `create table tb_purchaseOrder(
pur_id Integer not null PRIMARY KEY auto_increment, -- 采购订单号,主键,自增
pur_supplyId Integer not null, -- 供货商编号,外键
pur_date Date not null, -- 采购日期
pur_pay double not null, -- 支付总金额
pur_empId Integer not null, -- 员工编号,外键
pur_status tinyInt not null, -- 是否审核(0:未审核1:已审核通过 2:审核未通过退回采购员)
pur_mark Varchar(50), -- 备注
constraint fk_type_supply foreign key (pur_supplyId) references tb_supply (sup_id), -- 供应商编号是采购订单表的外键
constraint fk_type_employee2 foreign key (pur_empId) references tb_employee(emp_id) -- 员工编号是采购订单表的外键
);
alter table tb_purchaseOrder auto_increment = 20171001; -- 设置采购订单表编号从20171001开始递增`
9. 创建采购订单详情表(tb_purDetail)
* `create table tb_purDetail(
pDet_id Integer not null PRIMARY KEY auto_increment, -- 详单表编号,主键,自增
pDet_purId Integer not null, -- 采购订单表编号,外键
pDet_goodId Integer not null, -- 商品编号
pDet_number Integer not null, -- 采购数量
pDet_goodPrice double not null, -- 每种商品的进价总价格
pDet_status tinyInt not null, -- 采购状态(0:入库1:未入库)
pDet_mark Varchar(50), -- 备注
constraint fk_type_purchaseOrder foreign key (pDet_purId) references tb_purchaseOrder(pur_id), -- 采购订单表编号是采购订单详情表的外键
constraint fk_type_purchaseOrder2 foreign key (pDet_goodId) references tb_good(goods_id) -- 商品编号是采购订单表的外键
);`
10. 创建采购计划表(tb_purchasePlan)
* `create table tb_purchasePlan(
plan_id Integer not null PRIMARY KEY auto_increment, -- 主键,采购计划编号
plan_date Date not null, -- 计划日期
plan_empId Integer not null, -- 外键,员工编号
plan_mark varchar(50), -- 备注
constraint fk_type_employee1 foreign key (plan_empId) references tb_employee(emp_id) -- 员工编号是采购计划表的外键
);
alter table tb_purchasePlan auto_increment = 20173001; -- 设置采购计划表编号从20173001开始递增`
11. 创建采购计划详单表(tb_purPlanDetail)
* `create table tb_purPlanDetail(
planDet_id Integer not null PRIMARY KEY auto_increment, -- 计划详单表编号,主键,自增
planDet_purId Integer not null, -- 采购计划表编号,外键
planDet_goodId Integer not null, -- 商品编号
planDet_number Integer not null, -- 采购数量
planDet_goodPrice double not null, -- 每种商品的进价总价格
planDet_mark Varchar(50), -- 备注
constraint fk_type_purchasePlan foreign key (planDet_purId) references tb_purchasePlan(plan_id), -- 采购计划编号是采购计划详单表的外键
constraint fk_type_purchasePlan2 foreign key (planDet_goodId) references tb_good(goods_id) -- 商品编号是采购计划表的外键
);`
12. 创建销售订单表(tb_sellOrder)
* `CREATE TABLE tb_sellOrder (
sell_id INTEGER NOT NULL PRIMARY KEY auto_increment, -- 销售订单编号,主键
sell_empId INTEGER NOT NULL,-- 员工编号,外键
sell_date Date NOT NULL, -- 销售日期
sell_profit double NOT NULL, -- 销售总金额
sell_status INTEGER not null, -- 销售状态 (0:已销售,1:已退货,2:部分退货)
sell_mark varchar(50) DEFAULT NULL, -- 备注
constraint fk_type_employee3 foreign key (sell_empId) references tb_employee(emp_id) -- 员工编号是销售订单表的外键
);
alter table tb_sellOrder auto_increment = 20172001; --设置销售订单表编号从20172001开始`
13. 创建销售订单详情表(tb_sellDeteil)
* `CREATE TABLE tb_sellDetail (
sDet_id INTEGER NOT NULL PRIMARY KEY auto_increment,-- 销售订单编号,主键
sDet_sellId INTEGER NOT NULL, -- 销售订单号,外键
sDet_goodId INTEGER NOT NULL, -- 商品编号
sDet_number INTEGER NOT NULL, -- 销售数量
sDet_goodPrice DOUBLE NOT NULL,-- 每件商品的销售总金额
sDet_status tinyint NOT NULL, -- 销售状态(0:已销售 1:已退货)
sDet_mark varchar(50), -- 备注
constraint fk_type_sellOrder foreign key (sDet_sellId) references tb_sellOrder(sell_id), -- 销售订单表编号是销售订单详情表的外键
constraint fk_type_sellOrder2 foreign key (sDet_goodId) references tb_good(goods_id) -- 商品编号是销售订单表的外键
);`
插入数据
1. 插入供应商数据
* `insert into tb_supply(sup_name,sup_address,sup_linkMan,sup_phone,sup_status,sup_mark)VALUES
("阿里巴巴供应商","浙江杭州","马云","15096661111",1,"阿里巴巴首席执行官"),
("百度供应商","北京朝阳区","李彦宏","15096662222",1,"百度CEO"),
("腾讯供应商","广东深圳","马化腾","15096663333",1,"腾讯CEO"),
("京东供应商","北京朝阳区","刘强东","15096663333",1,"京东大老板");`
2. 插入职务信息表数据
* `insert into tb_position(posi_name ,posi_introduction)VALUES
("进货员","负责采购进货"),
("销售员","负责销售商品"),
("仓管员","负责管理仓库"),
("财务员","负责数钱");`
3. 插入员工信息表数据
* `insert into tb_employee(emp_name,emp_sex ,emp_password ,emp_position_id ,emp_phone ,emp_birthday ,emp_salary ,emp_status ,emp_mark )VALUES
("熊主席",0,"123456",1,"13272131111","1999-10-10",30000,1,"国服第一采购员,日常剁手采购"),
("小潘潘",1,"123456",2,"13272132222","2000-10-10",20000,1,"国服第一销售员,日常疯狂销售"),
("大佬",1,"123456",3,"13272133333","2010-10-10",1000000,1,"管的了仓库,写的了bug"),
("南哥",1,"123456",3,"13272134444","2003-10-10",2000000,1,"上得厅堂,下得厨房");`
4. 插入仓库表数据
* `insert into tb_storage(sto_name ,sto_empId ,sto_address ,sto_mark )VALUES
("主仓库",3,"美国纽约","小金库"),
("饮料库",3,"美国纽约","大仓库"),
("酒库",3,"美国纽约","中仓库"),
("零食库",3,"美国纽约","小仓库");`
5. 插入商品信息表数据
* `insert into tb_good(goods_name ,goods_units ,goods_size ,goods_purPrice ,goods_sellPrice ,goods_number ,goods_stoId ,goods_keepDays ,goods_minNumber ,goods_mark )VALUES
("桃子","个","100g",2.5,3.5,20,1,10,5,"甜的不行"),
("李子","个","80g",3.5,4.5,20,1,10,5,"甜的不行"),
("苹果","个","100g",2.5,3.5,20,1,10,5,"甜的不行"),
("冰红茶","瓶","350g",2,5,20,2,60,5,"解渴的不行"),
("红牛","瓶","350g",4,6,20,2,60,5,"解渴的不行"),
("伊利牛奶","瓶","350g",3,5,20,2,60,5,"解渴的不行"),
("82年拉菲","瓶","500g",1000,2000,20,3,100,5,"酒劲大的不行"),
("鸡尾酒","瓶","500g",6,12,20,3,100,5,"酒劲大的不行"),
("浏阳河","瓶","500g",500,700,20,3,100,5,"酒劲大的不行"),
("威龙","包","200g",3,5,100,4,20,5,"好吃的不行"),
("亲嘴烧","包","50g",0.1,0.5,100,4,20,5,"好吃的不行"),
("辣子鱼","包","100g",0.5,1,100,4,20,5,"好吃的不行");
insert into tb_good(goods_name ,goods_units ,goods_size ,goods_purPrice ,goods_sellPrice ,goods_number ,goods_stoId ,goods_keepDays ,goods_minNumber ,goods_mark )VALUES
("香蕉","个","100g",2.5,3.5,20,1,10,100,"甜的不行"),
("菠萝","个","80g",3.5,4.5,20,1,10,100,"甜的不行"),
("西瓜","个","100g",2.5,3.5,20,1,10,100,"甜的不行");`
6. 插入采购订单表数据
* `insert into tb_purchaseOrder(pur_supplyId ,pur_date ,pur_pay ,pur_empId ,pur_status ,pur_mark )VALUES
(1,"2017-8-12",0,1,0,"无备注"),
(2,"2015-8-12",0,1,0,"无备注"),
(3,"2014-8-12",0,1,0,"无备注"),
(4,"2015-8-12",0,1,0,"无备注"),
(1,"2016-8-12",0,1,0,"无备注"),
(2,"2013-8-12",0,1,0,"无备注"),
(3,"2017-8-12",0,1,0,"无备注"),
(4,"2014-8-12",0,1,0,"无备注"),
(2,"2017-8-12",0,1,0,"无备注"),
(1,"2014-8-12",0,1,0,"无备注"),
(2,"2013-8-12",0,1,0,"无备注"),
(3,"2013-8-12",0,1,0,"无备注");`
7. 插入采购订单详情表数据
* `insert into tb_purDetail(pDet_purId ,pDet_goodId ,pDet_number ,pDet_goodPrice ,pDet_status ,pDet_mark )VALUES
(20171001,10001,1,0,1,"无备注"),
(20171002,10002,1,0,1,"无备注"),
(20171003,10003,1,0,1,"无备注"),
(20171004,10004,1,0,1,"无备注"),
(20171005,10005,1,0,1,"无备注"),
(20171006,10006,1,0,1,"无备注"),
(20171007,10007,1,0,1,"无备注"),
(20171008,10008,1,0,1,"无备注"),
(20171009,10009,1,0,1,"无备注"),
(20171010,10010,1,0,1,"无备注"),
(20171001,10011,1,0,1,"无备注"),
(20171002,10012,1,0,1,"无备注");`
8. 插入采购计划表数据
* `insert into tb_purchasePlan(plan_date ,plan_empId ,plan_mark)VALUES
("2016-10-10",1,"无备注"),
("2017-10-10",1,"无备注"),
("2015-10-10",1,"无备注"),
("2014-10-10",1,"无备注"),
("2013-10-10",1,"无备注"),
("2016-10-10",1,"无备注");`
9. 插入采购订单详情表数据
* `insert into tb_purPlanDetail(planDet_purId,planDet_goodId,planDet_number,planDet_goodPrice,planDet_mark)VALUES
(20173001,10001,2,0,"无"),
(20173001,10002,3,0,"无"),
(20173001,10003,4,0,"无"),
(20173001,10004,5,0,"无"),
(20173001,10005,6,0,"无"),
(20173001,10006,7,0,"无"),
(20173002,10001,4,0,"无"),
(20173002,10002,6,0,"无");`
10. 插入销售订单表数据
* `insert into tb_sellOrder (sell_empId ,sell_date ,sell_profit ,sell_status ,sell_mark )VALUES
(2,"2010-10-10",0,0,"无备注"),
(2,"2012-10-10",0,0,"无备注"),
(2,"2013-10-10",0,0,"无备注"),
(2,"2012-10-10",0,0,"无备注"),
(2,"2013-10-10",0,0,"无备注"),
(2,"2014-10-10",0,0,"无备注");`
11. 插入销售订单详情表数据
* `insert into tb_sellDetail (sDet_sellId ,sDet_goodId ,sDet_number ,sDet_goodPrice ,sDet_status ,sDet_mark )VALUES
(20172001,10001,1,0,0,"无备注"),
(20172001,10002,2,0,0,"无备注"),
(20172001,10003,3,0,0,"无备注"),
(20172001,10004,4,0,0,"无备注"),
(20172001,10005,5,0,0,"无备注"),
(20172001,10006,6,0,0,"无备注"),
(20172002,10001,1,0,0,"无备注"),
(20172002,10002,1,0,0,"无备注"),
(20172002,10003,1,0,0,"无备注"),
(20172002,10004,1,0,0,"无备注"),
(20172003,10005,1,0,0,"无备注"),
(20172003,10006,1,0,0,"无备注"),
(20172004,10007,1,0,0,"无备注"),
(20172004,10008,1,0,0,"无备注"),
(20172004,10009,1,0,0,"无备注"),
(20172005,10002,1,0,0,"无备注"),
(20172005,10003,1,0,0,"无备注");`
Java项目专栏之数据库建表的更多相关文章
- 【Java框架型项目从入门到装逼】第九节 - 数据库建表和CRUD操作
1.新建学生表 这节课我们来把和数据库以及jdbc相关的内容完成,首先,进行数据库建表.数据库呢,我们采用MySQL数据库,我们可以通过navcat之类的管理工具来轻松建表. 首先,我们得建一个数据库 ...
- vue.js+koa2项目实战(六)数据库建表
数据库建表 1.打开 MySQL 终端 2.查看所有数据库 show databases 3.创建数据库 create database pet 4.进入数据库 use pet 5.创建数据表 cre ...
- PowerDesigner连接Oracle数据库建表序列号实现自动增长
原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...
- 字段自动递增的数据库建表的SQL写法
数据库建表的SQL写法如下: 数据库建表的SQL写法如下: create table dataC( a int identity(1,2) primary key, b varchar(20)) ...
- Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法
现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="or ...
- django 数据库建表流程,与表结构
目录 配置数据库 创建表结构 多表关连的设置 自创建关联表方法 自建表 和 ManyToManyField 联合使用 配置数据库 在Django项目的settings.py文件中,配置数据库连接信息: ...
- Java 项目JDBC 链接数据库中会出现的错误
1.出现的地方 package com.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql ...
- Mac下安装MySQL、Workbench以及建数据库建表最基础操作
刚用上Mac,什么都不懂,加之以前还没有用过mysql,就想着在Mac上装一个mysql来自己玩,奈何,在网上找了大半天,没有一个干货!愤怒!下面是我安装的过程,希望能帮到和我情况差不多的朋友 首 ...
- mysql数据库建表的基本规范
1.创建表的时候必须指定主键,并且主键建立后最好不要再有数据修改的需求 mysql从5.5版本开始默认使用innodb引擎,innodb表是聚簇索引表,也就是说数据通过主键聚集( 主键下存储该行的数据 ...
随机推荐
- 浮动(float)与清除浮动(clear)
上一篇中我们了解了块级元素与内联元素,今天将自己查阅的资料整理写出来,与大家一起理解什么是浮动,以及怎样清除浮动,本文以div元素为例. 浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮 ...
- CSS 换行问题white-space属性 window对象和global对象
white-space: nowrap禁止换行 1.word-wrap:break-word; 内容将在边界内换行,仅用于块对象,内联对象要用的话,必须要设定height.width或display: ...
- mybatis foreach批量插入数据:Oracle与MySQL区别
mybatis foreach批量插入数据:Oracle与MySQL不同点: 主要不同点在于foreach标签内separator属性的设置问题: separator设置为","分 ...
- MongoDB批量操作及与MySQL效率对比
本文主要通过批量与非批量对比操作的方式介绍MongoDB的bulkWrite()方法的使用.顺带与关系型数据库MySQL进行对比,比较这两种不同类型数据库的效率.如果只是想学习bulkWrite()的 ...
- js分享功能
引用JiaThis的分享功能: 直接在想要放置分享功能的地方加上如下代码即可: <!-- JiaThis Button BEGIN --> <div class="jiat ...
- CTF---Web入门第八题 Guess Next Session
Guess Next Session分值:10 来源: iFurySt 难度:易 参与人数:3870人 Get Flag:1672人 答题人数:1690人 解题通过率:99% 写个算法没准就算出来了, ...
- Java入门篇(四)——数组
上篇在foreach中有引入一个数组的概念,数组是最为常见的一种数据结构,是相同类型的.用一个标识符封装到一起的基本类型数据序列或对象序列. 数组是具有相同数据类型的一组数据的集合,根据维数不同可以分 ...
- Spider_Man_4 の BeautifulSoup
一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你 ...
- Python数据类型一:数字与运算符
数字 一.数值类型 python中支持的数值类型有以下几种: 1.整型(Int) - 通常被称为是整型或整数,是正或负整数,不带小数点.Python3 整型是没有限制大小的,可以当作 Long 类型使 ...
- java中的分支结构 switch case的使用
switch(A),括号中A的取值只能是整型或者可以转换为整型的数值类型,比如byte.short.int.char.string(jdk1.7后加入)还有枚举:需要强调的是:long是不能用在swi ...