UPDATE EST_PROD SET CD_CLASS_FISC = 0
WHERE NOT EXISTS (SELECT CD_CLASS_FISC 
				  FROM EST_TRIB_CLASS_FISC
				  WHERE CD_CLASS_FISC = CD_CLASS_FISC)

GO
 
IF  NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_EST_PROD_EST_TRIB_CLASS_FISC]') AND parent_object_id = OBJECT_ID(N'[dbo].[EST_PROD]'))
	BEGIN
		ALTER TABLE [dbo].[EST_PROD]  WITH NOCHECK ADD  CONSTRAINT [FK_EST_PROD_EST_TRIB_CLASS_FISC] FOREIGN KEY([CD_CLASS_FISC])
		REFERENCES [dbo].[EST_TRIB_CLASS_FISC] ([CD_CLASS_FISC])
		ON UPDATE CASCADE
		

		ALTER TABLE [dbo].[EST_PROD] CHECK CONSTRAINT [FK_EST_PROD_EST_TRIB_CLASS_FISC]
	END


