IF NOT EXISTS (SELECT *
                 FROM INFORMATION_SCHEMA.TABLES 
				WHERE TABLE_NAME = 'PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX'  
			   )
BEGIN
     CREATE TABLE PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX (
	      CD_EMP       INT NOT NULL, 
		  CD_FILIAL    INT NOT NULL, 
		  CD_CTR       INT NOT NULL, 
		  CD_CTR_ID   INT NOT NULL
         );
		  
    
     ALTER TABLE PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX ADD CONSTRAINT PK_PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX PRIMARY KEY (CD_EMP,CD_FILIAL,CD_CTR,CD_CTR_ID)
	 ALTER TABLE PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX ADD CONSTRAINT FK_PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX_CD_CTR_ID                  FOREIGN KEY (CD_CTR_ID)                REFERENCES PDV_NSU_QR_LINX (CD_CTR_ID) 
	 ALTER TABLE PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX ADD CONSTRAINT FK_PDV_CUPOM_NAO_FISCAL_PDV_NSU_QR_LINX_CD_EMP_CD_FILIAL_CD_CTR    FOREIGN KEY (CD_EMP,CD_FILIAL,CD_CTR)  REFERENCES PDV_CUPOM_NAO_FISCAL (CD_EMP,CD_FILIAL,CD_CTR) 
END;
