约束简述

--添加主键约束(即primary key约束)

 

alter table goods add constraint pk_gid primary key(gid)

 

--№1.删除主键约束

 

alter table goods drop pk_gid

 

--添加唯一约束(即unique约束)

 

alter table goods add constraint uq_gname unique(gname)

 

--删除唯一约束:仿№1.

 

--添加缺省约束(即default约束)

 

alter table goods add constraint def_gtel default 0000-00000000 for gtel

 

--删除缺省约束:仿№1.

 

--添加检查约束(即check约束)

 

alter table goods add constraint ck_gprice check(gprice>500)

 

--删除check约束:仿№1.

 

--创建表2

 

create table g_p

 

(

 

wno int identity(1,1) primary key,

 

gno int

 

)

 

--添加外键约束(即foreign key约束)

 

alter table g_p

 

add constraint fk_gno

 

foreign key(gno) references goods(gid)

 

--删除外键约束:仿№1.

 

 

--使用newid()

select newid()--生成全球唯一的ID号

 

create table customer

 

(

 

custID uniqueidentifier not null default newid(),

 

customer char(30) not null

 

)

 

posted @ 2008-11-08 20:11  玉玉  阅读(144)  评论(0编辑  收藏  举报