Sybase - Default Constraints
I need to drop all the default column level constraints on the table, in Sybase.
I dont have any idea how to do it, i had tried to disable the constraints with the following as below:
ALTER TABLE Employee NOCHECK CONSTRAINT ALL
The above does not work even, gives an error as below:
Error (156) Incorrect syntax near the keyword 'CONSTRAINT'
Also,开发者_如何转开发 I have tried with some custom stored proc, with the sys tables but that is NOT compliant with Sybase syntax, it works on SQL server, as below:
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
Can someone please solve this riddle ..
I am myself not very conversant with SQL but is it mandatory to solve this with SQL only? You can also write a script that fetches the schema at run time and figures out names of all constraints on a given table. Example,
sp_helpconstraint $tableName
Following this, you can use the following command:
alter table table_name
drop constraint constraint_name
For more details see the following references:
sp_helpconstraint
Dropping columns or column constraints.
In sybase ASE , If you want to delete Default constraint on a table then
Find the constraint name of that default constraint as
sp_helpconstraint TableName
now execute This query
alter table TableName drop constraint constraintname
精彩评论