IF OBJECT_ID('PDV_VD_IT_EST_RPS') IS NULL
BEGIN 
	CREATE TABLE PDV_VD_IT_EST_RPS (
		CD_EMP		INT, 
		CD_FILIAL	INT, 
		CD_VD		INT, 
		CD_IT		INT, 
		ID			BIGINT CONSTRAINT FK_PDV_VD_IT_EST_RPS_ID FOREIGN KEY REFERENCES EST_RPS (ID),
	  CONSTRAINT PK_PDV_VD_IT_EST_RPS PRIMARY KEY (CD_EMP, CD_FILIAL, CD_VD, CD_IT, ID)
	   ) 
END 
GO

IF OBJECT_ID('FK_PDV_VD_IT_EST_RPS_CD_EMP_CD_FILIAL_CD_VD')IS NULL
BEGIN 
	ALTER TABLE PDV_VD_IT_EST_RPS ADD CONSTRAINT FK_PDV_VD_IT_EST_RPS_CD_EMP_CD_FILIAL_CD_VD FOREIGN KEY  (CD_EMP, CD_FILIAL, CD_VD, CD_IT)  REFERENCES PDV_VD_IT (CD_EMP, CD_FILIAL, CD_VD, CD_IT)
END 
	 