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

  • 格式:txt
  • 大小:1.77 KB
  • 文档页数:1

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)

下载文档原格式

  / 1
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。