📄 t90erptable.sql
字号:
--***********仓库管理
--库区表:DepotSubarea
if exists(select * from sysobjects where name='DepotSubarea')
drop table DepotSubarea
create table DepotSubarea
(
Dsub_id int primary key identity(1,1) not null, --库区id 主键 自增 Int
Dsub_name varchar(10) not null,--库区名称 Varchar(10)
Dsub_type varchar(10) not null--仓库类别 Varchar(10)
)
go
--移动类型表:Transfer
if exists(select * from sysobjects where name='Transfer')
drop table Transfer
create table Transfer
(
Tran_id int primary key identity(1,1) not null, --移动类型id 主键 自增 Int
Tran_name varchar(20) not null --移动类型名称 Varchar(20)
)
go
--入库明细表:PutInfo
if exists(select * from sysobjects where name='PutInfo')
drop table PutInfo
create table PutInfo
(
Put_id Int primary key identity(1,1) not null, --入库明细id 主键 自增
Put_code Varchar(20) not null, --入库单代码 日期+随即数生成
Buybill_id Int not null, --采购单编号 外键
Put_time Datetime not null, --入库时间
Put_people varchar(20) not null, --入库人
Dsub_id Int not null, --库区 外键 级联删除
Tran_id Int not null --移动类型 外键
)
----约束
go
--库存表:Stock
if exists(select * from sysobjects where name='Stock')
drop table Stock
create table Stock
(
Stock_id Int primary key identity(1,1) not null, --库存编号 主键 自增
Dsub_id Int not null, --库区id 外键
Pro_id Int not null, --商品id 外键
Stock_number Int not null --商品数量
)
----约束
go
--出库明细表:OutInfo
if exists(select * from sysobjects where name='OutInfo')
drop table OutInfo
create table OutInfo
(
Out_id Int primary key identity(1,1) not null, --出库明细id 主键 自增
Out_code Varchar(20) not null, --出库单据号 唯一
Out_time Datetime not null, --出库时间
Out_llr Varchar(20) not null, --领料人
Out_flr Varchar(20) not null, --发料人
Out_tranId Int not null, --移动类型
Out_dsubId Int not null --库区
)
----约束
go
--补仓管理:RepairDepot
if exists(select * from sysobjects where name='RepairDepot')
drop table RepairDepot
create table RepairDepot
(
Repa_id Int primary key identity(1,1) not null, --补仓id 主键 自增
Pro_id Int not null, --商品id 外键
Repa_number Int not null, --补仓数量
Repa_dsubId Int not null, --库区表 外键
Repa_remark text null --备注 空,默认没有备注
)
----约束
go
--***********销售管理
--客户级别表(CustLevel)
if exists(select * from sysobjects where name='CustLevel')
drop table CustLevel
create table CustLevel
(
Cl_id Int primary key identity(1,1) not null, --编号 主,自增
Cl_name Varchar(10) not null, --级别名称
Cl_discount float not null --折扣
)
--约束
go
--客户信息表(customer)
if exists(select * from sysobjects where name='customer')
drop table customer
create table customer
(
C_id int primary key identity(1,1) not null, --编号 主,自动增长
C_number Varchar(10) not null, --客户代号
C_name Varchar(20) not null, --客户名称
C_linkman Varchar(20) not null, --联系人
C_phone Varchar(11) not null, --联系电话
C_address Text null, --公司地址 空,默认地址不详
Cl_id Int not null, --级别编号 外
C_remark text null, --备注信息 默认没有备注 空
)
--约束
go
--订单表(orders)
if exists(select * from sysobjects where name='orders')
drop table orders
create table orders
(
O_id int primary key identity(1,1) not null, --编号 主,自增
O_number Varchar(20) not null, --订单代码 日期+随即数生成
O_timestart datetime not null, --下单日期 下单时间必须在交货时间之前
O_timestop Datetime not null, --交货日期
O_money Money not null, --下单金额
C_id Int not null, --客户编号 外 级联删除
Emp_id int not null --员工编号 外
)
--约束
go
--订单明细表(OrderDetails)
if exists(select * from sysobjects where name='OrderDetails')
drop table OrderDetails
create table OrderDetails
(
Od_id Int primary key identity(1,1) not null, --编号 主,自增
O_id int not null, --订单编号 外
Pro_id int not null, --商品编号 外
Od_price Money not null, --单件金额
Od_accounts Int not null --单件数量
)
--约束
go
--销售单表(Sells)
if exists(select * from sysobjects where name='Sells')
drop table Sells
create table Sells
(
Sell_id int primary key identity(1,1) not null, --编号 主,自增
O_id int not null, --订单编号 外
Sell_timestart datetime not null, --销售日期 下单时间必须在交货时间之前
Sell_timestop Datetime not null, --交货日期
Sell_money Money not null, --销售金额
C_id Int not null, --客户编号 外
Emp_id int not null, --员工编号 外
Sell_remark text null --备注 空
)
--约束
go
--销售单明细表(SellDetails)
if exists(select * from sysobjects where name='SellDetails')
drop table SellDetails
create table SellDetails
(
Selld_id int primary key identity(1,1) not null, --编号 主,自增
O_id int not null, --订单编号
Pro_id int not null, --商品编号
Selld_price Money not null, --单件金额
Selld_accounts Int not null --单件数量
)
--约束
go
--***********财务管理
--财务科目表:FinaSub
if exists(select * from sysobjects where name='FinaSub')
drop table FinaSub
create table FinaSub
(
Fina_id Int primary key identity(1,1) not null, --科目编号 主,自增
Fina_name Varchar(50) not null, --科目名称
Fina_accounts Varchar(50) not null, --银行账号 随机数生成
Fina_people Varchar(50) not null, --联系人
Fina_telephone Varchar(11) not null, --联系电话
Fina_mode Varchar(10) not null, --是借或贷
Fina_play Varchar(10) not null, --借贷方式(现金、发票)
Fian_money money not null --金额
)
go
--发票信息表:Invoice
if exists(select * from sysobjects where name='Invoice')
drop table Invoice
create table Invoice
(
Invo_id Int primary key identity(1,1) not null, --发票编号 主,自增
Invo_code Varchar(50) not null, --发票单据号 日期+随机数生成,唯一
Invo_type Varchar(10) not null, --发票类型
Invo_money money not null, --金额
Invo_use Varchar(50) not null, --发票用途
Invo_datetime Datetime not null, --发票日期
Emp_id int not null --财务员编号 外,职员表
)
----约束
go
--固定资产表:FixedAssets
if exists(select * from sysobjects where name='FixedAssets')
drop table FixedAssets
create table FixedAssets
(
Fix_id Int primary key identity(1,1) not null, --资产编号 主,自增
Fix_name Varchar(100) not null, --资产名称
Fix_money Money not null, --可汇兑金额
Fix_datetime Datetime not null, --添加时间
Fix_remark Text null, --备注 空,默认没有备注
)
----约束
go
--财务员统计视图
--***********权限管理
--用户表:UserInfo
if exists(select * from sysobjects where name='UserInfo')
drop table UserInfo
create table UserInfo
(
u_id int primary key identity(1,1) not null, --用户编号,主,自增
u_name varchar(20) not null, --用户名,即登录名
u_pass varchar(10) not null, --登录密码
u_time datetime not null --登录时间
)
--insert into UserInfo values('admin','admin','2008-08-05')
--insert into UserInfo values('yqh','yqh','2008-08-05')
--insert into UserInfo values('gogo','gogo','2008-08-05')
--insert into UserInfo values('wangwang','wangwang','2008-08-05')
select * from UserInfo
go
--角色表:RolesInfo
if exists(select * from sysobjects where name='RolesInfo')
drop table RolesInfo
create table RolesInfo
(
r_id int primary key identity(1,1) not null, --角色编号,主,自增
r_name varchar(20) not null, --角色名称,即职位名称,唯一
r_desc text null --角色描述,空,默认没有描述
)
alter table RolesInfo add constraint UQ_r_name unique (r_name)
alter table RolesInfo add constraint DF_r_desc default ('没有描述') for r_desc
--insert into RolesInfo values('系统管理员','可以有任何操作')
--insert into RolesInfo values('总经理','最高管理者')
--insert into RolesInfo values('部门经理','管理者')
--insert into RolesInfo values('普通员工',default)
select * from RolesInfo
go
--用户和角色中间表(因为是、一对多的关系):UserRolesCenter
if exists(select * from sysobjects where name='UserRolesCenter')
drop table UserRolesCenter
create table UserRolesCenter
(
c_id int primary key identity(1,1) not null, --中间表编号,主,自增
u_id int not null, --外,用户编号,修改和删除规则都是层叠
r_id int not null --外,角色编号,修改和删除规则都是层叠
)
alter table UserRolesCenter add constraint FK_u_id foreign key (u_id) references UserInfo(u_id)
alter table UserRolesCenter add constraint FK_r_id foreign key (r_id) references RolesInfo(r_id)
--insert into UserRolesCenter values(1,1)
--insert into UserRolesCenter values(1,2)
--insert into UserRolesCenter values(2,2)
--insert into UserRolesCenter values(3,3)
--insert into UserRolesCenter values(4,4)
select * from UserRolesCenter
--delete from UserRolesCenter where c_id=5
--查询视图
select * from UserRolesView
--查询角色1中已有的用户,利用视图
select * from UserRolesView where r_id=1
--查询角色1中没有的用户,利用子查询,用户表中的所有用户减去角色中已有的用户
Select * from UserInfo where u_id not in (select u_id from UserRolesView where r_id=1)
go
--菜单表:MenuInfo
if exists(select * from sysobjects where name='MenuInfo')
drop table MenuInfo
create table MenuInfo
(
M_id Int primary key identity(1,1) not null,--菜单编号 主,自增
M_name Varchar(50) not null,--菜单名称
M_url Varchar(50) null,--菜单链接 空
M_parentId int not null,--父菜单编号
)
--约束
--insert into MenuInfo values('系统权限管理','',0)
--insert into MenuInfo values('人力资源管理','',0)
--insert into MenuInfo values('采购管理','',0)
--insert into MenuInfo values('仓库管理','',0)
--insert into MenuInfo values('销售管理','',0)
--insert into MenuInfo values('财务管理','',0)
select * from MenuInfo
go
--4.角色和菜单中间表即权限表:PowerInfo
if exists(select * from sysobjects where name='PowerInfo')
drop table PowerInfo
create table PowerInfo
(
P_id Int primary key identity(1,1) not null,--权限编号 主
R_id Int not null,--角色编号 外 ,修改和删除规则都是层叠
M_id int not null,--菜单编号 外 ,修改和删除规则都是层叠
)
--约束
alter table PowerInfo add constraint FK_pr_id foreign key (r_id) references RolesInfo(r_id)
alter table PowerInfo add constraint FK_m_id foreign key (m_id) references MenuInfo(m_id)
--insert into PowerInfo values(1,1)
--insert into PowerInfo values(1,2)
--insert into PowerInfo values(2,2)
--insert into PowerInfo values(3,3)
--insert into PowerInfo values(4,4)
select * from PowerInfo
--查询视图
select * from RolesMenuView
--查询角色1中已有的功能,利用视图
select * from RolesMenuView where r_id=1
--查询角色1中没有的功能,利用子查询,菜单表中的所有功能减去角色中已有的功能
Select * from MenuInfo where m_id not in (select m_id from RolesMenuView where r_id=1)
go
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -