Skip to content
Advertisement

Change all bit columns to int with default value NULL

I have a database where we would store Yes/No questions as bits. However, as the project is going to a different path, we need to change all bit data types to int with default value NULL.

Trying the following query, I get object is dependent of column error.

ALTER TABLE dbo.Customers ALTER COLUMN **[Is item returned?]** int not null;

To fix this I try doing:

ALTER TABLE dbo.Customers DROP CONSTRAINT DF_Customers_[Is item returned?]
ALTER TABLE dbo.Customers ALTER COLUMN [Is item returned?] int not null
ALTER TABLE dbo.Customers WITH NOCHECK ADD CONSTRAINT [DF_Customers_[Is item returned?]] DEFAULT NULL FOR [Is item returned?]

However, the fact that the column is in [brackets] is making this throw syntax errors. Should this be fixed with quotes? What are your opinions?

Advertisement

Answer

The solution is I had to add more brackets as delimiters to fix the syntax. The following query works perfectly:

ALTER TABLE dbo.Customers DROP CONSTRAINT [DF_Customers_Is item returned?]
ALTER TABLE dbo.Customers ALTER COLUMN [Is item returned?] int not null
ALTER TABLE dbo.Customers WITH NOCHECK ADD CONSTRAINT [DF_Customers_Is item returned?] DEFAULT NULL FOR [Is item returned?]
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement