IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO]') AND type in (N'U'))
BEGIN 
	  
	CREATE TABLE [dbo].[EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO](
	[CD_CTR_ERROS] [int] IDENTITY(1,1) NOT NULL,
	[CD_CTR] [int] NOT NULL DEFAULT 0,
	[DT_CAD] [datetime] NOT NULL DEFAULT getdate(),
	[ERROS_VALIDACAO] [xml] NOT NULL,
	[STS_ERRO] [int] NOT NULL DEFAULT 0,
	[CD_USU] [int] NOT NULL DEFAULT 0,
	[DT_CAD_CORRECAO] [datetime] NOT NULL DEFAULT getdate(),
	[VERSAO_APLIC] [varchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[CD_MOV_OP] [int] NULL DEFAULT 0,
	 CONSTRAINT [PK_EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO] PRIMARY KEY CLUSTERED 
		(
			[CD_CTR_ERROS] ASC
		 )
	) 

	ALTER TABLE [dbo].[EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO_EST_NF_ENT_DANFE_CTE] FOREIGN KEY([CD_CTR])
	REFERENCES [dbo].[EST_NF_ENT_DANFE_CTE] ([CD_CTR])

	ALTER TABLE [dbo].[EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO] CHECK CONSTRAINT [FK_EST_NF_ENT_DANFE_CTE_ERROS_VALIDACAO_EST_NF_ENT_DANFE_CTE]
 
END