Skip to content

Instantly share code, notes, and snippets.

@derjabkin
Created April 30, 2013 10:34
Show Gist options
  • Save derjabkin/5487903 to your computer and use it in GitHub Desktop.
Save derjabkin/5487903 to your computer and use it in GitHub Desktop.
SQL Server: Delete all Constraints for a column
Create Proc [dbo].[Proc_DropConstraints]
@TableName sysname,
@ColumnName sysname
as
Declare @SQL nvarchar(1000)
Declare RS Cursor local read_only for
Select 'Alter Table ' + @TableName+
' drop constraint '+ quotename(object_name(constid))
from sysconstraints where id=object_id(@TableName) and
colid=(Select colid from syscolumns where id=sysconstraints.id and
name like @ColumnName)
Open RS
fetch next from RS into @SQL
while @@FETCH_STATUS=0
begin
exec sp_executesql @SQL
fetch next from RS into @SQL
end
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment