IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE NAME = 'CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT')
BEGIN
	CREATE TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT](
		[CD_FND_VERBA_FECHAMENTO] [int] NOT NULL,
		[CD_FND_VERBA] [int] NOT NULL,
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_VD] [int] NOT NULL,
		[CD_IT] [int] NOT NULL,
	 CONSTRAINT [PK_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT] PRIMARY KEY CLUSTERED 
	(
		[CD_FND_VERBA_FECHAMENTO] ASC,
		[CD_FND_VERBA] ASC,
		[CD_EMP] ASC,
		[CD_FILIAL] ASC,
		[CD_VD] ASC,
		[CD_IT] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
	) ON [PRIMARY]
end
GO

IF OBJECT_ID('DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_EMP') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT] ADD  CONSTRAINT [DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]
GO

IF OBJECT_ID('DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_FILIAL') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT] ADD  CONSTRAINT [DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]
GO

IF OBJECT_ID('DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_VD') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT] ADD  CONSTRAINT [DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_VD]  DEFAULT ((0)) FOR [CD_VD]
GO

IF OBJECT_ID('DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_IT') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT] ADD  CONSTRAINT [DF_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_IT]  DEFAULT ((0)) FOR [CD_IT]
GO

IF OBJECT_ID('FK_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_FECHAMENTO') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT]  WITH CHECK ADD  CONSTRAINT [FK_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_FECHAMENTO] FOREIGN KEY([CD_FND_VERBA_FECHAMENTO])
REFERENCES [dbo].[CG_FND_VERBA_FECHAMENTO] ([CD_FND_VERBA_FECHAMENTO])

ALTER TABLE [dbo].[CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT] CHECK CONSTRAINT [FK_CG_FND_VERBA_FECHAMENTO_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_FECHAMENTO]