Wednesday, 10 September 2008
Alter a column with a default value
say you wanted to change a BIT column to a NVARCHAR column, and the BIT column has a default value set to 0 or 1. you can't run the following statement or you get a dependent object error.
alter table TABLE1 alter column COL1 NVarChar(MAX)
so i found this solution here
, after you've run the query below, you can alter the column as above.
DECLARE @df SYSNAME
SET @df =
WHERE id = OBJECT_ID('dbo.TABLE1')
AND name = 'COL1')
IF @df IS NOT NULL
EXEC sp_rename @df, 'df_to_drop', 'OBJECT'
ALTER TABLE dbo.TABLE1 DROP CONSTRAINT df_to_drop
Wednesday, 10 September 2008 10:46:01 (GMT Daylight Time, UTC+01:00) Database