IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE NAME = 'CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT')
BEGIN
	CREATE TABLE [dbo].[CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT](
		[CD_EMP] [int] NOT NULL,
		[CD_FND_VERBA] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_VD] [int] NOT NULL,
		[CD_IT] [int] NOT NULL,
		[CD_FND_VERBA_RECB] [int] NOT NULL,
	 CONSTRAINT [PK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_1] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_FND_VERBA] ASC,
		[CD_FILIAL] ASC,
		[CD_VD] ASC,
		[CD_IT] ASC,
		[CD_FND_VERBA_RECB] 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_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_EMP') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT] ADD  CONSTRAINT [DF_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]
GO

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

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

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


IF OBJECT_ID('FK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_RECB') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT]  WITH CHECK ADD  CONSTRAINT [FK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_RECB] FOREIGN KEY([CD_FND_VERBA_RECB], [CD_FND_VERBA], [CD_EMP])
REFERENCES [dbo].[CG_FND_VERBA_RECB] ([CD_FND_VERBA_RECB], [CD_FND_VERBA], [CD_EMP])

ALTER TABLE [dbo].[CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT] CHECK CONSTRAINT [FK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_RECB]
GO

IF OBJECT_ID('FK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_GERACAO_PDV_VD_IT') IS NULL 
ALTER TABLE [dbo].[CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT]  WITH CHECK ADD  CONSTRAINT [FK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_GERACAO_PDV_VD_IT] FOREIGN KEY([CD_EMP], [CD_FND_VERBA], [CD_FILIAL], [CD_VD], [CD_IT])
REFERENCES [dbo].[CG_FND_VERBA_GERACAO_PDV_VD_IT] ([CD_EMP], [CD_FND_VERBA], [CD_FILIAL], [CD_VD], [CD_IT])

ALTER TABLE [dbo].[CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT] CHECK CONSTRAINT [FK_CG_FND_VERBA_RECB_CG_FND_VERBA_GERACAO_PDV_VD_IT_CG_FND_VERBA_GERACAO_PDV_VD_IT]