IF not EXISTS( SELECT * FROM
		sys.FOREIGN_KEYS
	WHERE  OBJECT_ID = OBJECT_ID(N'FK_EST_PROD_TRANSF_LACRE_IT_EST_PROD_TRANSF_LACRE')
)
	BEGIN
		DELETE EST_PROD_TRANSF_LACRE_IT
		FROM EST_PROD_TRANSF_LACRE_IT
			 LEFT OUTER JOIN EST_PROD_TRANSF_LACRE ON EST_PROD_TRANSF_LACRE_IT.CD_EMP = EST_PROD_TRANSF_LACRE.CD_EMP
													  AND EST_PROD_TRANSF_LACRE_IT.CD_FILIAL = EST_PROD_TRANSF_LACRE.CD_FILIAL
													  AND EST_PROD_TRANSF_LACRE_IT.CD_CTR = EST_PROD_TRANSF_LACRE.CD_CTR
													  AND EST_PROD_TRANSF_LACRE_IT.NR_LACRE = EST_PROD_TRANSF_LACRE.NR_LACRE
		WHERE
			  EST_PROD_TRANSF_LACRE.CD_EMP IS NULL;
		ALTER TABLE EST_PROD_TRANSF_LACRE_IT ALTER COLUMN NR_LACRE VARCHAR(150) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS NOT NULL;
		
		ALTER TABLE EST_PROD_TRANSF_LACRE_IT WITH CHECK ADD 
			CONSTRAINT FK_EST_PROD_TRANSF_LACRE_IT_EST_PROD_TRANSF_LACRE FOREIGN KEY(CD_EMP, CD_FILIAL, CD_CTR, CD_LACRE) REFERENCES EST_PROD_TRANSF_LACRE(
																																	 CD_EMP
																																   , CD_FILIAL
																																   , CD_CTR
																																   , CD_LACRE) ON UPDATE CASCADE ON DELETE CASCADE;
	END; 