2011-05-25 104 views
0

我需要在Sybase中删除表上的所有默认列级约束。Sybase - 默认约束条件

我没有任何想法如何做到这一点,我曾试图用如下以下禁用的约束:

ALTER TABLE Employee NOCHECK CONSTRAINT ALL 

上面甚至不工作,给出了如下错误:

Error (156) Incorrect syntax near the keyword 'CONSTRAINT' 

而且,我已经尝试了一些自定义的存储过程,用sys表,但就是不符合语法的Sybase,它的工作原理的SQL服务器上,如下图所示:

declare @sql varchar(1024) 
declare curs cursor for 
select 'ALTER TABLE '+tab.name+' DROP CONSTRAINT '+cons.name 
from sysobjects cons,sysobjects tab 
where cons.type in ('D') 
    and cons.parent_object_id=tab.object_id and tab.type='U' 
order by cons.type 

open curs 
fetch next from curs into @sql 
while (@@fetch_status = 0) 
begin 
exec(@sql) 
fetch next from curs into @sql 
end 
close curs 
deallocate curs 

有人可以解决这个谜语吗?

回答

0

我自己不是很熟悉SQL,但它是强制性的,只用SQL解决这个问题?您还可以编写一个脚本,用于在运行时提取模式,并计算给定表上所有约束的名称。例如,

sp_helpconstraint $tableName 

在此之后,你可以使用下面的命令:

alter table table_name 
drop constraint constraint_name 

欲了解更多详细信息,请参阅以下参考资料:

sp_helpconstraint

Dropping columns or column constraints

-1

在Sybase ASE,如果你想删除一个表的默认约束,则

查找默认约束的约束名称

sp_helpconstraint可将表名

现在执行这个查询

alter table TableName掉落约束约束名称