IF EXISTS (SELECT * FROM SYS.columns WHERE NAME = 'ENVIA_WMS' AND object_id = OBJECT_ID('EST_PROD_CD_BARRA'))
BEGIN
	DECLARE @NM_CONSTRAINT NVARCHAR(max)
	
	select @NM_CONSTRAINT=name FROM SYS.default_constraints WHERE parent_object_id = OBJECT_ID('EST_PROD_CD_BARRA') and name like '%envia%'


	SET @NM_CONSTRAINT ='ALTER TABLE EST_PROD_CD_BARRA DROP CONSTRAINT ' + @NM_CONSTRAINT
	
	
	EXECUTE SP_EXECUTESQL @NM_CONSTRAINT
	
	ALTER TABLE EST_PROD_CD_BARRA DROP COLUMN ENVIA_WMS;
	
	ALTER TABLE EST_PROD_CD_BARRA ADD NAO_ENVIA_WMS INT ;
	
	ALTER TABLE EST_PROD_CD_BARRA ADD CONSTRAINT DF_EST_PROD_NAO_ENVIA_WMS DEFAULT (0) FOR NAO_ENVIA_WMS
	
	PRINT 'Campo criado.'
END
ELSE
BEGIN
	IF NOT EXISTS (SELECT * FROM SYS.columns WHERE NAME = 'NAO_ENVIA_WMS' AND object_id = OBJECT_ID('EST_PROD_CD_BARRA'))
	BEGIN	
	
		ALTER TABLE EST_PROD_CD_BARRA ADD NAO_ENVIA_WMS INT ;
	
		ALTER TABLE EST_PROD_CD_BARRA ADD CONSTRAINT DF_EST_PROD_NAO_ENVIA_WMS DEFAULT (0) FOR NAO_ENVIA_WMS
	END
END