DECLARE @STRING_SQL VARCHAR(500)

IF EXISTS (SELECT 1 FROM SYS.DEFAULT_CONSTRAINTS WHERE OBJECT_ID IN (SELECT DEFAULT_OBJECT_ID  FROM SYS.COLUMNS WHERE NAME = 'FLAG_HABILITA_USO_2FA' AND OBJECT_ID = OBJECT_ID('GLB_USU')))
BEGIN
	SELECT @STRING_SQL = 'ALTER TABLE GLB_USU DROP CONSTRAINT ' + NAME 
	FROM SYS.DEFAULT_CONSTRAINTS WHERE OBJECT_ID IN (SELECT DEFAULT_OBJECT_ID  FROM SYS.COLUMNS WHERE NAME = 'FLAG_HABILITA_USO_2FA' AND OBJECT_ID = OBJECT_ID('GLB_USU'))

	EXEC (@STRING_SQL)

END

IF EXISTS (SELECT 1 FROM SYS.COLUMNS WHERE NAME = 'FLAG_HABILITA_USO_2FA' AND OBJECT_ID = OBJECT_ID('GLB_USU'))
BEGIN
	ALTER TABLE [dbo].[GLB_USU] ADD CONSTRAINT DF_GLB_USU_FLAG_HABILITA_USO_2FA DEFAULT 1 FOR [FLAG_HABILITA_USO_2FA]

	UPDATE [GLB_USU] SET [FLAG_HABILITA_USO_2FA]=1

END 