IF OBJECT_ID ('RC_CLI_FIDELI_CARTAO_CONV') IS NULL 
    BEGIN 
	   CREATE TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV](
		   [CD_EMP] [INT] NOT NULL,
		   [CD_CLI] [INT] NOT NULL,
		   [NR_CARTAO] varchar (20) NOT NULL,
		   [CD_CONV] [INT] NOT NULL,
	    CONSTRAINT [PK_RC_CLI_FIDELI_CARTAO_CONV] PRIMARY KEY CLUSTERED 
	   (
		   [CD_EMP] ASC,
		   [CD_CLI] ASC,
		   [CD_CONV] ASC
	   )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	   ) ON [PRIMARY]
 

	   ALTER TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV]  WITH CHECK ADD  CONSTRAINT [FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI] FOREIGN KEY([CD_EMP], [CD_CLI])
	   REFERENCES [DBO].[RC_CLI] ([CD_EMP], [CD_CLI])
 

	   ALTER TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV] CHECK CONSTRAINT [FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI]
 

	   ALTER TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV]  WITH CHECK ADD  CONSTRAINT [FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI_CONV] FOREIGN KEY([CD_EMP], [CD_CONV])
	   REFERENCES [DBO].[RC_CLI_CONV] ([CD_EMP], [CD_CONV])
 

	   ALTER TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV] CHECK CONSTRAINT [FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI_CONV]
 

	  /* ALTER TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV]  WITH CHECK ADD  CONSTRAINT [FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI_FIDELI_CARTAO] FOREIGN KEY([NR_CARTAO], [CD_CLI], [CD_EMP])
	   REFERENCES [DBO].[RC_CLI_FIDELI_CARTAO] ([NR_CARTAO], [CD_CLI], [CD_EMP])*/
 

	   ALTER TABLE [DBO].[RC_CLI_FIDELI_CARTAO_CONV] CHECK CONSTRAINT [FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI_FIDELI_CARTAO]
 

	   ALTER TABLE RC_CLI_FIDELI_CARTAO_CONV
	   ADD CONSTRAINT FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI_CONV FOREIGN KEY(CD_EMP, CD_CONV) REFERENCES RC_CLI_CONV(CD_EMP,
																							  CD_CONV)
	   /*ALTER TABLE RC_CLI_FIDELI_CARTAO_CONV
	   ADD CONSTRAINT FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI_FIDELI_CARTAO FOREIGN KEY(NR_CARTAO, CD_CLI, CD_EMP) REFERENCES RC_CLI_FIDELI_CARTAO (NR_CARTAO, CD_CLI, CD_EMP)*/
 
	   ALTER TABLE RC_CLI_FIDELI_CARTAO_CONV
	   ADD CONSTRAINT FK_RC_CLI_FIDELI_CARTAO_CONV_RC_CLI FOREIGN KEY(CD_EMP, CD_CLI) REFERENCES RC_CLI (CD_EMP, CD_CLI)
    END