Quantcast
Channel: SQL Server 2005 drop column with constraints - Stack Overflow
Viewing all articles
Browse latest Browse all 14

Answer by Jeremy Stein for SQL Server 2005 drop column with constraints

$
0
0

Here is a script that will delete the column along with its default constraint. Replace MYTABLENAME and MYCOLUMNNAME appropriately.

declare @constraint_name sysname, @sql nvarchar(max)select @constraint_name = name from sys.default_constraints where parent_object_id = object_id('MYTABLENAME')AND type = 'D'AND parent_column_id = (    select column_id     from sys.columns     where object_id = object_id('MYTABLENAME')    and name = 'MYCOLUMNNAME'    )set @sql = N'alter table MYTABLENAME drop constraint '+ @constraint_nameexec sp_executesql @sqlalter table MYTABLENAME drop column MYCOLUMNNAMEgo

Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>