DECLARE @table_id AS INT
DECLARE @Updated BIT

-- Find table id
SET @table_id = OBJECT_ID('Allotments')

IF Exists (select * from sys.columns c
inner join sys.types t on c.user_type_id = t.user_type_id and t.name = 'bit'
where c.name = 'active' and object_id = @table_id)
BEGIN
	DECLARE @name_column_id AS INT
	DECLARE @sql nvarchar(255) 

	

	-- Find name column id
	SELECT @name_column_id = column_id
	FROM sys.columns
	WHERE object_id = @table_id
	AND name = 'Active'

	-- Remove default constraint from name column
	SELECT @sql = 'ALTER TABLE Allotments DROP CONSTRAINT ' + D.name
	FROM sys.default_constraints AS D
	WHERE D.parent_object_id = @table_id
	AND D.parent_column_id = @name_column_id

	EXECUTE sp_executesql @sql

	ALTER TABLE dbo.Allotments ALTER COLUMN Active INT NOT NULL 
	ALTER TABLE dbo.Allotments
	  ADD CONSTRAINT DF_Allotment_Active_Default
	  DEFAULT 0 FOR Active

	
 END