IF OBJECT_ID('RC_DEB_PDV_CUPOM_NAO_FISCAL') IS NULL

BEGIN

     CREATE TABLE RC_DEB_PDV_CUPOM_NAO_FISCAL
           (CD_EMP            INT NOT NULL,
            CD_FILIAL         INT NOT NULL,
            CD_RC_DEB         INT NOT NULL,
            CD_CTR            INT NOT NULL,
            CD_FILIAL_SANGRIA INT NOT NULL
          
     CONSTRAINT PK_RC_DEB_PDV_CUPOM_NAO_FISCAL PRIMARY KEY CLUSTERED (CD_EMP ASC, CD_FILIAL ASC, CD_RC_DEB ASC, CD_CTR ASC)
);
        ALTER TABLE RC_DEB_PDV_CUPOM_NAO_FISCAL
        ADD CONSTRAINT FK_RC_DEB_PDV_CUPOM_NAO_FISCAL_RC_DEB FOREIGN KEY(CD_EMP, CD_FILIAL, CD_RC_DEB) REFERENCES RC_DEB(CD_EMP, CD_FILIAL, CD_RC_DEB);
        ALTER TABLE RC_DEB_PDV_CUPOM_NAO_FISCAL
        ADD CONSTRAINT FK_RC_DEB_PDV_CUPOM_NAO_FISCAL_PDV_CUPOM_NAO_FISCAL FOREIGN KEY(CD_EMP, CD_FILIAL_SANGRIA, CD_CTR) REFERENCES PDV_CUPOM_NAO_FISCAL(CD_EMP, CD_FILIAL, CD_CTR);
END;