约束的问题?
constraint和check有什么区别?是不是都称为约束?
[解决办法]
if object_id('t') is not nulldrop table tgocreate 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约束。