IF OBJECT_ID('CG_FND_VERBA_NOTA_CREDITO_PG_FORN') IS NULL
begin
CREATE TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN](
	[CD_CTR_NOTA_CREDITO] [int] NOT NULL,
	[CD_EMP] [int] NOT NULL,
	[CD_FORN] [int] NOT NULL,
 CONSTRAINT [PK_CG_FND_VERBA_NOTA_CREDITO_PG_FORN] PRIMARY KEY CLUSTERED 
(
	[CD_CTR_NOTA_CREDITO] ASC,
	[CD_EMP] ASC,
	[CD_FORN] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_CG_FND_VERBA_NOTA_CREDITO_PG_FORN] UNIQUE NONCLUSTERED 
(
	[CD_FORN] ASC,
	[CD_EMP] 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 [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN] ADD  CONSTRAINT [DF_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_CD_CTR_NOTA_CREDITO]  DEFAULT ((0)) FOR [CD_CTR_NOTA_CREDITO]

ALTER TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN] ADD  CONSTRAINT [DF_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN] ADD  CONSTRAINT [DF_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_CD_FORN]  DEFAULT ((0)) FOR [CD_FORN]

ALTER TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN]  WITH CHECK ADD  CONSTRAINT [FK_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_CG_FND_VERBA_NOTA_CREDITO] FOREIGN KEY([CD_CTR_NOTA_CREDITO])
REFERENCES [dbo].[CG_FND_VERBA_NOTA_CREDITO] ([CD_CTR_NOTA_CREDITO])

ALTER TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN] CHECK CONSTRAINT [FK_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_CG_FND_VERBA_NOTA_CREDITO]

ALTER TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN]  WITH CHECK ADD  CONSTRAINT [FK_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_PG_FORN] FOREIGN KEY([CD_EMP], [CD_FORN])
REFERENCES [dbo].[PG_FORN] ([CD_EMP], [CD_FORN])

ALTER TABLE [dbo].[CG_FND_VERBA_NOTA_CREDITO_PG_FORN] CHECK CONSTRAINT [FK_CG_FND_VERBA_NOTA_CREDITO_PG_FORN_PG_FORN]
end