IF OBJECT_ID('EST_RPS_NFSE_VALID')IS NULL 
 BEGIN 
CREATE TABLE EST_RPS_NFSE_VALID(
	RPS_ID				bigint		NOT NULL,
	CD_EMP				integer		NOT NULL,
	CD_FILIAL			Integer		NOT NULL,
	INDENTIFICACAO		varchar(100) NULL,
	RPS_SUBSTITUIDO		int NULL,
	CODIGO_VERIFICACAO	varchar(100) NULL,
	CHAVE_ACESSO		varchar(100) NULL,
	STATUS				int NULL,


 CONSTRAINT [EST_RPS_NFE_VALID_IDX] PRIMARY KEY CLUSTERED ([RPS_ID] 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 EST_RPS_NFSE_VALID  WITH CHECK ADD  CONSTRAINT [EST_RPS_NFE_VALID_FK] FOREIGN KEY(RPS_ID)
REFERENCES EST_RPS (ID)
ON DELETE CASCADE;


ALTER TABLE [EST_RPS_NFSE_VALID] CHECK CONSTRAINT [EST_RPS_NFE_VALID_FK]

END


