IF OBJECT_ID('PG_CRED_CONTROLE') IS NULL
begin
CREATE TABLE [dbo].[PG_CRED_CONTROLE](
	[CD_PG_CRED_CONTROLE] [int] IDENTITY(1,1) NOT NULL,
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_PG_CRED] [int] NOT NULL,
 CONSTRAINT [PK_PG_CRED_CONTROLE] PRIMARY KEY CLUSTERED 
(
	[CD_PG_CRED_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]


ALTER TABLE [dbo].[PG_CRED_CONTROLE] ADD  CONSTRAINT [DF_PG_CRED_CONTROLE_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[PG_CRED_CONTROLE] ADD  CONSTRAINT [DF_PG_CRED_CONTROLE_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]


ALTER TABLE [dbo].[PG_CRED_CONTROLE] ADD  CONSTRAINT [DF_PG_CRED_CONTROLE_CD_PG_CRED]  DEFAULT ((0)) FOR [CD_PG_CRED]


ALTER TABLE [dbo].[PG_CRED_CONTROLE]  WITH CHECK ADD  CONSTRAINT [FK_PG_CRED_CONTROLE_PG_CRED] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PG_CRED])
REFERENCES [dbo].[PG_CRED] ([CD_EMP], [CD_FILIAL], [CD_PG_CRED])
ON UPDATE CASCADE
ON DELETE CASCADE

ALTER TABLE [dbo].[PG_CRED_CONTROLE] CHECK CONSTRAINT [FK_PG_CRED_CONTROLE_PG_CRED]
end

