RSS 2.0 | Atom 1.0 | CDF

Search

Categories

Archive

Blogroll

Sign In

# Wednesday, September 10, 2008
Wednesday, September 10, 2008 10:46:01 AM (GMT Daylight Time, UTC+01:00) ( Database )
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 = 
 (SELECT OBJECT_NAME(cdefault) 
  FROM SYSCOLUMNS 
  WHERE id = OBJECT_ID('dbo.TABLE1') 
   AND name = 'COL1') 
IF @df IS NOT NULL 
 BEGIN 
  EXEC sp_rename @df, 'df_to_drop', 'OBJECT' 
  ALTER TABLE dbo.TABLE1 DROP CONSTRAINT df_to_drop 
 END

Comments [0] | | #