DELETE
	PG_CRED_CONTROLE
FROM
	PG_CRED_CONTROLE LEFT OUTER JOIN PG_CRED ON
	PG_CRED_CONTROLE.CD_EMP = PG_CRED.CD_EMP AND
	PG_CRED_CONTROLE.CD_FILIAL = PG_CRED.CD_FILIAL AND
	PG_CRED_CONTROLE.CD_PG_CRED = PG_CRED.CD_PG_CRED 
WHERE
	PG_CRED.CD_PG_CRED  IS NULL
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PG_CRED_CONTROLE_PG_CRED]'))
begin
	ALTER TABLE [dbo].[PG_CRED_CONTROLE] DROP CONSTRAINT [FK_PG_CRED_CONTROLE_PG_CRED]
end
GO
ALTER TABLE dbo.PG_CRED_CONTROLE 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 
	