IF NOT EXISTS
(
    SELECT *
    FROM   SYS.TABLES
    WHERE  NAME = 'ADM_ERRO_PDV_VD_INTEGRACOES'
)
	BEGIN

		/****** Object:  Table [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES]    Script Date: 13/01/2017 09:53:59 ******/
		SET ANSI_NULLS ON

		SET QUOTED_IDENTIFIER ON

		CREATE TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES](
			[CD_CONTROLE] [int] IDENTITY(1,1) NOT NULL,
			[CD_VD] [int] NOT NULL,
			[CD_CX] [int] NOT NULL,
			[NR_ECF] [int] NOT NULL,
			[CD_FILIAL] [int] NOT NULL,
			[DT_CAD] [datetime] NULL,
			[DT_VD] [datetime] NOT NULL,
			[JSON_ENVIADO] [varchar](max) NOT NULL,
			[STS_ERRO] [int] NOT NULL,
			[CD_USU_CORRECAO] [int] NULL,
			[DT_CORRECAO] [datetime] NULL,
			[LAUDO] [varchar](500) NULL,
			[CODIGO] [int] NULL,
		 CONSTRAINT [PK_ADM_ERRO_PDV_VD_INTEGRACOES_1] PRIMARY KEY CLUSTERED 
		(
			[CD_CONTROLE] ASC
		)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
		) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_CD_VD]  DEFAULT ((0)) FOR [CD_VD]

		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_CD_CX]  DEFAULT ((0)) FOR [CD_CX]

		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_NR_ECF]  DEFAULT ((0)) FOR [NR_ECF]

		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_STS_ERRO]  DEFAULT ((0)) FOR [STS_ERRO]

		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_CD_USU_CORRECAO]  DEFAULT ((0)) FOR [CD_USU_CORRECAO]

		ALTER TABLE [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES] ADD  CONSTRAINT [DF_ADM_ERRO_PDV_VD_INTEGRACOES_CODIGO]  DEFAULT ((0)) FOR [CODIGO]
		
		CREATE NONCLUSTERED INDEX [IX_ADM_ERRO_CAD_BASICOS_INTEGRACOES_CD_VD_CD_CX_NR_ECF_CD_FILIAL_DT_CAD] ON [dbo].[ADM_ERRO_PDV_VD_INTEGRACOES]
		(
			[CD_VD] ASC,
			[CD_CX] ASC,
			[NR_ECF] ASC,
			[CD_FILIAL] ASC,
			[DT_CAD] ASC
		)
		WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	
		
	END


