日期:2014-05-18  浏览次数:20425 次

约束的问题?
constraint和check有什么区别?是不是都称为约束?

------解决方案--------------------
SQL code

if object_id('t') is not null
drop table t
go
create table t(
id int constraint [pk_t] primary key,
name nvarchar(20) constraint [uk_t_name] unique,
idate datetime constraint [df_t_idate] default(getdate()),
price float not null,
constraint [ck_t] check(price>=0)
)
go
--constraint只是声明一个约束,check只是约束的一种类型,还有其他约束
--pk_t为主键约束
--uk_t_name为唯一键约束
--df_t_idate为默认值约束
--check为检查约束,此处检查价格>0

------解决方案--------------------
constraint声明所有约束,CHECK只是CHECK约束。