当前位置:文档之家› 数据库仓库相关表的创建代码

数据库仓库相关表的创建代码

Create schema 订货
Create table 订货.仓库
(仓库号 char(6) primary key check(substring(仓库号,1,2)>='AA' and substring(仓库号,1,2)<='ZZ' and
substring(仓库号,3,4)>='0000' and substring(仓库号,3,4)<='9999'),
城市 char(10) unique not null,
面积 numeric check(面积 >=50)
)

create table 订货.职工
(职工号 char(8) primary key check(substring(职工号 ,7,2)>='00' and substring( 职工号,7,2)<='99'),
仓库号 as convert(char(6),substring(职工号,1,6)) persisted foreign key references 订货.仓库(仓库号),
经理 char(8) foreign key references 订货.职工(职工号) null,
工资 money check(工资 between 1000 and 10000)
)

create table 订货.供应商
(供应商号 char(4) primary key check(substring(供应商号 ,1,1)='S' and substring(供应商号 ,2,3)>='000' and
substring(供应商号 ,2,3)<='999'),
供应商名 char(16),
地址 char(30)
)


create table 订货.订购单
(职工号 char(8) foreign key references 订货.职工(职工号) not null,
供应商号 char(4) foreign key references 订货.供应商(供应商号) null,
订购单号 char(6) primary key check(substring(订购单号 ,1,2)='OR'and substring(订购单号 ,3,4)>='000' and
substring(订购单号 ,3,4)<='999') ,
订购日期 datetime default getdate(),
金额 money default null)


create table 订货.订购单明细
(订购单号 char(6) not null foreign key references 订货.订购单,
序号 smallint,
产品名称 char(20),
单价 money check(单价>0) default null,
数量 bigint check(数量>0) not null
primary key (订购单号,序号))


alter table 订货.订购单
add 完成日期 datetime default null


alter table 订货.订购单明细
drop column 数量
add 数量 int check(数量>0 and 数量<=1000) not null


alter table 订货.供应商
alter column 供应商名 varchar(30)
add 数量 int check(数量>0 and 数量<=1000) not null


alter table 订货.供应商
alter column 供应商名 varchar(30)

相关主题
文本预览
相关文档 最新文档