if not exists(select * from INFORMATION_SCHEMA.tables 
			 where table_name='PDV_VD_RPS_CANCEL') 

/*
=======================================================================================
'Nível Classificação.: INFORMAÇÃO RESTRITA
'Versão..............: 2022013
'Job.................:  
'Nome................: EST_RPS_IT 
'Objetivo............:  
'Tabelas.............: 
'Dt Criação..........: 13/01/2022
'Dt Ult Alteracão....: 
'Alterado por........: 
'Criado por..........: Marcos Barros 
'=======================================================================================
2022013 - criado tabela
*/

begin
CREATE TABLE PDV_VD_RPS_CANCEL (
	CD_EMP		INT,
	CD_FILIAL	INT,
	CD_CANCEL	INT,
	ID_RPS		bigint,
	ID_RPS_IT	bigint,
	TP_CANCEL	INT,
	DT_CANCEL	DATETIME 	
	CONSTRAINT [PK_PDV_VD_RPS_CANCEL] PRIMARY KEY CLUSTERED ([CD_EMP] ASC, [CD_FILIAL] ASC,	[CD_CANCEL] ASC, [ID_RPS] ASC,	[ID_RPS_IT] 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 [PDV_VD_RPS_CANCEL]  WITH CHECK ADD  CONSTRAINT [FK_PDV_VD_RPS_CANCELID_RPS] FOREIGN KEY(CD_EMP, CD_FILIAL, ID_RPS)   REFERENCES [EST_RPS] (CD_EMP, CD_FILIAL, ID);
	ALTER TABLE [PDV_VD_RPS_CANCEL]  WITH CHECK ADD  CONSTRAINT [FK_PDV_VD_RPS_CANCELID_ID_RPS_IT] FOREIGN KEY(CD_EMP, CD_FILIAL, ID_RPS, ID_RPS_IT)   REFERENCES [EST_RPS_IT] (CD_EMP, CD_FILIAL, RPS_ID, ID);

    ALTER TABLE [PDV_VD_RPS_CANCEL] CHECK CONSTRAINT [FK_PDV_VD_RPS_CANCELID_RPS]
	ALTER TABLE [PDV_VD_RPS_CANCEL] CHECK CONSTRAINT [FK_PDV_VD_RPS_CANCELID_ID_RPS_IT]
end

