IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'DBO.PDV_CUPOM_NAO_FISCAL_CARTAO_LINX_PROMO') AND TYPE IN (N'U'))
BEGIN
	CREATE TABLE PDV_CUPOM_NAO_FISCAL_CARTAO_LINX_PROMO(
		CD_EMP					INT NOT NULL,
		CD_FILIAL				INT NOT NULL,
		CD_CX					INT NOT NULL,
		CD_CTR					INT NOT NULL,
		CD_CARTAO_LINX_PROMO	INT NULL,
		DT_VENDA				DATETIME NOT NULL,
		CPF_CNPJ				VARCHAR(14) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS NOT NULL,
		IDENTIFICACAO_CARTAO	VARCHAR(30) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS NOT NULL,
        VALOR					MONEY NOT NULL,
		CD_FRM_PGTO				INT NOT NULL,
		CONSTRAINT PK_PDV_CUPOM_NAO_FISCAL_CARTAO_LINX_PROMO PRIMARY KEY (CD_EMP, CD_FILIAL, CD_CTR)
	)
END 
GO 

IF OBJECT_ID('FK_PDV_CUPOM_NAO_FISCAL_CARTAO_LINX_PROMO') IS NULL
BEGIN 
	ALTER TABLE PDV_CUPOM_NAO_FISCAL_CARTAO_LINX_PROMO ADD CONSTRAINT FK_PDV_CUPOM_NAO_FISCAL_CARTAO_LINX_PROMO FOREIGN KEY  (CD_EMP, CD_FILIAL, CD_CTR) REFERENCES PDV_CUPOM_NAO_FISCAL (CD_EMP, CD_FILIAL, CD_CTR)
END 