IF COL_LENGTH('Cbtes_Tipos', 'Compromete_Entregas') IS NULL 
BEGIN
	ALTER TABLE Cbtes_Tipos ADD Compromete_Entregas SMALLINT DEFAULT(0)
END
ELSE
BEGIN
	DECLARE @ConstraintName nvarchar(200)
	SELECT @ConstraintName = Name FROM SYS.DEFAULT_CONSTRAINTS
	WHERE PARENT_OBJECT_ID = OBJECT_ID('Cbtes_Tipos')
	AND PARENT_COLUMN_ID = (SELECT column_id FROM sys.columns
							WHERE NAME = N'Compromete_Entregas'
							AND object_id = OBJECT_ID(N'Cbtes_Tipos'))
	IF @ConstraintName IS NOT NULL
		EXEC('ALTER TABLE Cbtes_Tipos DROP CONSTRAINT ' + @ConstraintName)

	ALTER TABLE Cbtes_Tipos ALTER COLUMN Compromete_Entregas SMALLINT 
END
GO
UPDATE Cbtes_Tipos SET Compromete_Entregas = 0 WHERE Compromete_Entregas IS NULL




