⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t90erptable.sql

📁 数据库表ERP表参考。仅供参考
💻 SQL
📖 第 1 页 / 共 2 页
字号:
--------语法
--建立视图
--if exists(select * from sysobjects where name='视图名')
--	drop view 视图名
--go
--create view 视图名
--as
--select 字段名 from 表名 [条件]
--go

--主外健约束语句没有执行


use T90ERP
go

--***********人力资源

--部门表:Depet
if exists(select * from sysobjects where name='Depet')
	drop table Depet
go
create table Depet
(
dept_id Int primary key identity(1,1) not null,   --部门编号	主键,自增
dept_name	Varchar(20) not null                  --部门名称
)
----约束
--alter table Depet add constraint UQ_dept_name unique (dept_name)
go


--职位表:Post
if exists(select * from sysobjects where name='Post')
	drop table Post
go
create table Post
(
Post_id	Int primary key identity(1,1) not null,        --职位编号	主键  自增	
Post_name	Varchar(50) not null,                      --职位名称	唯一	
Post_money	Money not null,                            --职位工资		
Dept_id	int not null                               --部门编号	外	Int 级联删除
)
----约束
--alter table post add constraint UQ_post_name unique (post_name)
alter table post add constraint FK_post_deptId foreign key(post_deptId) references depet(dept_id)
go


--员工信息表:Employee
if exists(select * from sysobjects where name='Employee')
	drop table Employee
go
create table Employee
(
Emp_id	Int primary key identity(1,1) not null,    --员工信息编号	主键,自增		
Emp_number	Varchar(50) not null,                  --员工工号		唯一	
Emp_postId	Int not null,                          --职位编号	外键	级联删除	
Emp_hire	Datetime not null,                     --录用时间			
Emp_state	Bit not null,                          --状态	默认1 (1在职/0离职)		
)
----约束
--alter table Employee add constraint UQ_emp_number unique (emp_number)
alter table Employee add constraint FK_emp_postId foreign key (emp_postId) references post(post_id)
--alter table Employee add constraint DF_emp_state default(1) for emp_state
go


--简历表:Resume
if exists(select * from sysobjects where name='Resume')
	drop table Resume
go
create table Resume
(
Res_id Int  primary key identity(1,1) not null,    --职员信息ID	主键	非空自增	Int 
Emp_id	Int not null,                          --职员ID	外键		 
Res_name	Varchar(50) not null,                  --真实姓名			
Res_englishname	Varchar(50) null,                  --英文名		空	
Res_idcard	Varchar(19) not null,                  --身份证号		唯一索引 只有18位数字或18位数字加X	
Res_sex		bit  not null,                         --性别 默认1 男	只有男和女两种	
Res_bornDate	datetime  not null,                --出生年月			
Res_nativeplace varchar(50)  not null,             --籍贯			
Res_nation	Varchar(50)  not null,                 --民族	默认汉族		
Res_health	text  null,                         --健康状况 空	默认健康		
Res_diploma 	Varchar(50)  not null,             --学历			
Res_address	Varchar(50) null,                      --联系地址		空,默认地址不详	
Res_Tel	Varchar(50) not null,                      --电话	只能是11为数字		
Res_photo	image  null                        --照片		空	
)
----约束
alter table Resume add constraint FK_res_empid foreign key (res_empid) references Employee(emp_id)
--alter table Resume add constraint UQ_res_idcard unique (res_idcard)
--alter table Resume add constraint CK_res_idcard check (res_idcard like '[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]
--[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]' or res_idcard like '[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]
--[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]X')
--alter table Resume add constraint DF_res_sex default (1) for res_sex
--alter table Resume add constraint CK_res_sex check(res_sex=1 or res_sex=0)
--alter table Resume add constraint DF_res_nation default ('汉族') for res_nation
--alter table Resume add constraint DF_res_health default ('健康') for res_health
--alter table Resume add constraint DF_res_health defatult(1) for res_health
--alter table Resume add constraint DF_res_address default ('地址不详') for res_address
--alter table Resume add constraint CK_res_tel check(len(res_tel)=11)
go


--考勤类型表:CheckType
if exists(select * from sysobjects where name='CheckType')
	drop table CheckType
create table CheckType
(
Checkt_id int primary key identity(1,1) not null,	--考勤类型	主键	自增	Int
Checkt_name	varchar(50) not null                    --考勤名称(干什么)			Varchar(50)
)
go


--考勤表:Check
if exists(select * from sysobjects where name='CheckInfo')
	drop table CheckInfo
create table CheckInfo
(
Check_id int primary key identity(1,1) not null,	--考勤id	主键	自增	Int
Emp_id int not null,	                        --员工id	外键		Int
Check_hire	datetime not null,                      --考勤开始时间		开始时间必须	Datetime 
Check_end	datetime not null,                      --考勤结束时间		要在结束时间之前	Datatime
Checkt_id	int not null,                       --考勤类型	外键		Int
Check_gtime	 int not null,                          --工休天数			Int
check_time	int not null                            --扣薪天数			Int
)
----约束
alter table CheckInfo add constraint FK_check_empId foreign key (check_empId) references Employee(emp_id)
alter table CheckInfo add constraint FK_check_checktId foreign key (check_empId) references checkt(checkt_id)
--alter table CheckInfo add constraint CK_check_hire check(check_hire<check_end)
--alter table CheckInfo add constraint CK_check_end check(check_end>check_hire)
go


--培训管理:Train
if exists(select * from sysobjects where name='Train')
	drop table Train
create table Train
(
Train_id  int primary key identity(1,1) not null,	--培训编号	主键	自增	Int
Train_time	datetime not null,                      --培训日期			Datetime 
Train_address	varchar(200) not null,              --地址			Varchar(200) 
Train_content	text not null,                      --内容			text
Emp_id 	int not null,                       --职员编号			Int
Train_teacher varchar(20) not null	                --讲师			Varchar(20)
)
go

--奖罚记录类型:PrizeAmerceType
if exists(select * from sysobjects where name='PrizeAmerceType')
	drop table PrizeAmerceType
create table PrizeAmerceType
(
Prizet_id  int primary key identity(1,1) not null,	--奖罚记录类型id 	主键	自增	Int
Prizet_name	varchar(50) not null,                   --奖罚记录名称			Varchar(50) 
Prizet_money money not null	                        --奖罚金额			Money 
)
go


--奖罚记录表:PrizeAmerceRecord
if exists(select * from sysobjects where name='PrizeAmerceRecord')
	drop table PrizeAmerceRecord
create table PrizeAmerceRecord
(
Prize_id int primary key identity(1,1) not null,	--奖罚记录id	主键	自增	Int 
Emp_id int not null,	                        --员工id 	外键		Int
Prize_time datetime not null,	                    --时间			Datetime
Prizet_id	int not null,                       --引用奖罚类型id	外键		Int
Prize_desc	text null,                              --描述	空,默认没有描述		text
)
----约束
--alter table PrizeAmerceRecord add constraint FK_prize_empid foreign key(prize_empId) references Employee(emp_id)
--alter table PrizeAmerceRecord add constraint FK_prize_prizetid foreign key(prize_prizetId) references PrizeAmerceType(prizet_id)
alter table PrizeAmerceRecord add constraint DF_prize_desc default('没有描述') for prize_desc
go


--档案:Record
if exists(select * from sysobjects where name='Record')
	drop table Record
create table Record
(
Re_id int primary key identity(1,1) not null,	--档案id 	主键	自增	Int
Re_code	varchar(50) not null,                   --档案代码 日期+随即数生成 Varchar(50)
Emp_id int not null,	                        --员工id 	外键		Int
Prize_id	int not null                        --奖罚记录id	外键		Int
)
----约束
--alter table Record add constraint FK_re_empId foreign key (re_empId) references Employee(emp_id)
go


--薪资表:SalaryInfo
if exists(select * from sysobjects where name='SalaryInfo')
	drop table SalaryInfo
create table SalaryInfo
(
Sal_id int primary key identity(1,1) not null,	--薪水表ID	主键	自增	Int 
Emp_id int not null,	                        --职员ID	外键		Int 
Sal_bonus money not null,	                    --奖金			Money 
Sal_deduct	numeric(18,2) not null,             --扣除			Numerica(18,2)
Sal_tax	money not null,                         --扣税			Money 默认为0
Sal_sum	 money not null,                        --总薪水			Money 
Sal_date smalldatetime not null	                --发放日期			smalldatetime
)
----约束
--alter table SalaryInfo add constraint FK_sal_empid  foreign key (sal_empId) references Employee(emp_id)
go



--***********采购管理


--供应商级别:LevelInfo 
if exists(select * from sysobjects where name='LevelInfo')
	drop table LevelInfo
create table LevelInfo
(
Level_id int primary key identity(1,1) not null,	--级别编号	主	自增	Int
Level_name varchar(10) not null	                    --级别名称			Varchar(10)
)
go


--供应商:Victualer 
if exists(select * from sysobjects where name='Victualer')
	drop table Victualer
create table Victualer
(
Victu_id int primary key identity(1,1) not null,    --供应商编号	主	自增	Int
Victu_name	varchar(100) not null,                  --名称			Varchar(100)
Level_id	int not null,                       --级别编号	外,LevelInfo表		Int
Victu_people	varchar(20) not null,               --联系人			Varchar(20)
Victu_telephone varchar(11) not null,	            --联系电话			Varvhar(11),必须是11位
Victu_email	varchar(50) null,                       --邮件		空,必须符合邮件格式	Varchar(50)
Victu_address text not null,                        --联系地址			Text 默认地址不详
Victu_remark text null                              --备注		空,默认没有备注	Text
)
----约束
--alter table Victualer add constraint FK_Victu_levelId foreign key(Victu_levelId) references LevelInfo(Level_id)
alter table Victualer add constraint CK_Victu_telephone check(len(victu_telephone)=11)
alter table Victualer add constraint CK_Victu_email check(victu_email like '%@%.%')
alter table Victualer add constraint DF_Victu_remark default ('没有描述') for victu_remark
alter table Victualer add constraint DF_Victu_address default ('地址不详') for victu_address
go


--商品类别:Sort 
if exists(select * from sysobjects where name='Sort')
	drop table Sort
create table Sort
(
Sort_id	int primary key identity(1,1) not null,   --类别编号	主	自增	Int
Sort_name varchar(50) not null	                  --类别名称			Varchar(50)
)
go


--商品规格表:Spec 
if exists(select * from sysobjects where name='Spec')
	drop table Spec
create table Spec
(
Spec_id	int primary key identity(1,1) not null,   --规格编号	主	自增	Int
Spec_name	varchar(50) not null                  --规格名称			Varchar(50)
)
go


--商品表:Product 
if exists(select * from sysobjects where name='Product')
	drop table Product
create table Product
(
Pro_id int primary key identity(1,1) not null,	--商品编号	主	自增	Int
Pro_code varchar(20) not null,	                --商品代码		按日期+随机数生成,唯一 	Varchar(20)
Pro_name varchar(50) not null,                  --商品名称			Varchar(50)
Sort_id int not null,	                    --类别编号	外,Sort表		Int
Spec_id int not null,	                    --规格编号	外,Spec表		Int
Pro_count int not null,	                        --数量			Int
Pro_inPrice	money not null,                     --进货价			Money
Pro_outPrice  money not null,                   --销售价			Money
Victu_id	int not null,                       --供应商编号	外,Victualer表		Int 级联删除
Pro_remark	text null                           --备注		空,默认没有备注	Text
)
----约束
go


--询价单:AskPrice
if exists(select * from sysobjects where name='AskPrice')
	drop table AskPrice
create table AskPrice
(
Ask_id int primary key identity(1,1) not null,	 --询价单编号	主	自增	Int
Victu_id	int not null,                        --供应商编号	外,Victualer表		Int
Pro_id int not null,                          --商品编号	外,Product表		Int
ask_price money not null,	                     --报价			Money
Ask_time datetime not null                       --添加时间			Datetime
)
----约束
go



--采购单: BuyBill 
if exists(select * from sysobjects where name='BuyBill')
	drop table BuyBill
create table BuyBill
(
Buybill_id	int primary key identity(1,1) not null,  --采购单编号	主	自增	Int
Buybill_num varchar(20) not null, 	                 --采购单据号		按日期+随机数生成,唯一	varchar(20)
Emp_id int not null,	                         --采购员编号	外,职员表		Int
Buybill_time datetime not null,	                     --采购时间		采购时间必须在交货时间之前	Datetime
Buybill_delitime datetime not null,	                 --交货时间			Datetime
Buybill_remark	text not null,                       --合同备注			Text
Buybill_Isexam bit not null	                         --库管是否审批			bit
)
----约束
go



--采购明细表: BuyList 
if exists(select * from sysobjects where name='BuyList')
	drop table BuyList
create table BuyList
(
Buylist_id int primary key identity(1,1) not null,	--采购明细编号	主	自增	Int
Buybill_id	int not null,                   --采购单编号	外,Buybill表		Int
Pro_id	int not null,                       --商品编号	外,Prduct表		Int
Buylist_Count	int not null,                       --采购数量			Int
Buylist_price	money not null,                     --采购价			Money
Victu_id	int not null,                       --供应商编号	外,Vitcualer表		Int
Dsub_id	int not null                        --采购单商品仓库编号	外,DepotSubarea表		Int
)
----约束
go



--采购付款单:PayBill
if exists(select * from sysobjects where name='PayBill')
	drop table PayBill
create table PayBill
(
Pay_id int primary key identity(1,1) not null,	--付款单编号	主	自增	Int
Buybill_id	int not null,                   --采购单编号	外,Buybill表		Int
Pay_oncoming	money not null,                 --此次付款		如果应付款分为几次付	Money
Pay_deal	money not null,                     --应付款		则应付款应该要保持一致	Money
Emp_id	int not null,                       --财务部审批人编号	外,职员表		Int
Pay_Isexam	bit not null,                       --财务部是否审批			bit
Pay_remark	text null                           --备注		空,默认没有备注	text
)
----约束
go



--采购退货单:MoveBill
if exists(select * from sysobjects where name='MoveBill')
	drop table MoveBill
create table MoveBill
(
Move_id	int primary key identity(1,1) not null,   --退货单编号	主	自增	Int
Buybill_id	int not null,                     --采购单编号	外,Buybill表		Int
Move_time	datetime not null,                    --退单日期		退单日期必须是在采购日期之后	Datetime
Dsub_id	int not null,                     --库管审批人编号	外,		Int
Move_Isexam	 bit not null,                        --库管是否审批			Bit
Move_remark	text null                             --备注		空,默认没有备注	Text
)
----约束
go

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -