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

求助(关于SQL修改check约束条件)
我建了一个表:create table 订单名细
(订单号 char(8) foreign key references 订购单(订单号),
序号 tinyint,
产品号 char(8) foreign key references 产品(产品号) not null,
数量 smallint check(数量>0)
primary key
)
然后想 ”数量“字段的约束条件改为”小于等于1000的正数“,请问用alter table命令该怎么修改?
为什么我这样写会报错:在关键字 'check' 附近有语法错误。
请各位高手指点!!!

------解决方案--------------------
--查出约束名:
select object_name(constid) from sysconstraints where ID=object_id('表名') and colid>0 and status%16=4

go
alter table 表名 drop constraint 约束名

go
alter table 表名 add constraint 约束名 check(数量<=1000)