
 IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'EST_PROD_COD_BENEF_TP_MOV')
 
BEGIN  
    CREATE TABLE EST_PROD_COD_BENEF_TP_MOV (
        CD_CTR					INT             IDENTITY (1,1),  
		CD_EMP                  INT, 
		CD_PROD			    	INT             NOT NULL,
		UF						VARCHAR(2)      NOT NULL,
		CD_BENEF				VARCHAR(10)     NOT NULL,
		CD_TRIB_FC				VARCHAR(5)	    NOT NULL, 
    	TP_MOV					INT             NOT NULL, 
    	MOTIVO_DESONERADO_ICMS  VARCHAR(100)
    );
 
    ALTER TABLE EST_PROD_COD_BENEF_TP_MOV ADD CONSTRAINT PK_EST_PROD_COD_BENEF_TP_MOV PRIMARY KEY (CD_BENEF,CD_TRIB_FC,UF,CD_PROD,TP_MOV); 
    ALTER TABLE EST_PROD_COD_BENEF_TP_MOV ADD CONSTRAINT FK_EST_PROD_COD_BENEF_TP_MOV_CD_BENEF   FOREIGN KEY (CD_BENEF,CD_TRIB_FC) REFERENCES  TBL_CBENEF_CST (CD_BENEF,CD_TRIB_FC);
    ALTER TABLE EST_PROD_COD_BENEF_TP_MOV ADD CONSTRAINT FK_EST_PROD_COD_BENEF_TP_MOV_CD_PROD    FOREIGN KEY (CD_EMP,CD_PROD) REFERENCES  EST_PROD (CD_EMP,CD_PROD);
    ALTER TABLE EST_PROD_COD_BENEF_TP_MOV ADD CONSTRAINT FK_EST_PROD_COD_BENEF_TP_MOV_TP_MOV     FOREIGN KEY (TP_MOV) REFERENCES  GLB_MOV_OP_TP_MOV (TP_MOV);
   
END; 