create table EMP
(
Eno char(4) primary key,
Ename char(10),
Eage smallint,
Esalary money,
Edno char(4),
);
go
create table DEPT
(
Dno char(4) primary key,
Dbudget money,
Emno char(4),
foreign key (Emno) references EMP(Eno)
);
go
alter table EMP add
constraint fk foreign key (Edno) references DEPT(dno);
创建规则并绑定
create rule domain_age as @age <= 60
USE practise
EXEC sp_bindrule 'domain_age', 'EMP.Eage'
设置规则
ALTER TABLE EMP WITH NOCHECK
ADD CONSTRAINT age_check CHECK (Eage < 60)
添加主码和关联外码
alter table 订单信息
add 订单编号 nvarchar(50) constraint pk_订单 primary key,
add constraint fk_cp foreign key (产品编码) references 产品基础信息(产品编码),
add constraint fk_gys foreign key (供应商代码) references 供应商基础信息(供应商代码),
add constraint fk_kh foreign key (客户编号) references 客户基础信息(客户编号),
add constraint fk_kq foreign key (库区编号) references 库区基础信息(库区编号);
--设置主码
alter table 订单信息
add primary key(订单编号, 产品编码, 库区编号, 客户编号, 供应商代码);
阅读(794) | 评论(0) | 转发(0) |