DELETE
	I
FROM
	EST_SNGPC_REINICIO_INVENTARIO_IT I LEFT OUTER JOIN EST_PROD_EST_SNGPC_LOTE_CPL P ON
	I.CD_EMP = P.CD_EMP AND
	I.CD_FILIAL = P.CD_FILIAL AND
	I.CD_LOTE = P.CD_LOTE
WHERE
	P.CD_LOTE IS NULL
go
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_EST_SNGPC_REINICIO_INVENTARIO_IT_EST_PROD_EST_SNGPC_LOTE_CPL]'))
begin
	ALTER TABLE dbo.EST_SNGPC_REINICIO_INVENTARIO_IT
		DROP CONSTRAINT FK_EST_SNGPC_REINICIO_INVENTARIO_IT_EST_PROD_EST_SNGPC_LOTE_CPL
end
GO
ALTER TABLE dbo.EST_SNGPC_REINICIO_INVENTARIO_IT ADD CONSTRAINT
	FK_EST_SNGPC_REINICIO_INVENTARIO_IT_EST_PROD_EST_SNGPC_LOTE_CPL FOREIGN KEY
	(
	CD_EMP,
	CD_FILIAL,
	CD_LOTE
	) REFERENCES dbo.EST_PROD_EST_SNGPC_LOTE_CPL
	(
	CD_EMP,
	CD_FILIAL,
	CD_LOTE
	) ON UPDATE CASCADE 
	 ON DELETE  CASCADE 