IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE ID = OBJECT_ID('EST_TRIB_CONF_GRP') AND name = 'CD_CLASS_FISC')
begin
	ALTER TABLE EST_TRIB_CONF_GRP ADD CD_CLASS_FISC INT
	ALTER TABLE EST_TRIB_CONF_GRP ADD CONSTRAINT DF_EST_TRIB_CONF_GRP_CD_CLASS_FISC DEFAULT 0 FOR CD_CLASS_FISC 
	
	ALTER TABLE [dbo].[EST_TRIB_CONF_GRP]  WITH NOCHECK ADD  CONSTRAINT [FK_EST_TRIB_CONF_GRP_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_TRIB_CONF_GRP] CHECK CONSTRAINT [FK_EST_TRIB_CONF_GRP_EST_TRIB_CLASS_FISC]
		
end
GO
 
UPDATE EST_TRIB_CONF_GRP SET CD_CLASS_FISC  = 0 
WHERE CD_CLASS_FISC IS NULL												

