IF COL_LENGTH('dbo.Prod_Familias', 'Id_Form_Rem') IS NULL
ALTER TABLE Prod_Familias ADD Id_Form_Rem VARCHAR(10)


IF COL_LENGTH('dbo.Prod_Familias', 'Id_Form_Fac') IS NULL
ALTER TABLE Prod_Familias ADD Id_Form_Fac VARCHAR(10)



IF NOT EXISTS( SELECT 1 FROM sys.indexes WHERE name = 'IX_PROFAM_PorFormRem' AND object_id = OBJECT_ID('Prod_Familias') ) 
CREATE INDEX IX_PROFAM_PorFormRem ON Prod_Familias (Id_Form_Rem,Descripcion)


IF NOT EXISTS( SELECT 1 FROM sys.indexes WHERE name = 'IX_PROFAM_PorFormFac' AND object_id = OBJECT_ID('Prod_Familias') ) 
CREATE INDEX IX_PROFAM_PorFormFac ON Prod_Familias (Id_Form_Fac,Descripcion)



IF NOT EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS  WHERE CONSTRAINT_NAME='FK_PROFAM_PorFormRem' )
ALTER TABLE Prod_Familias ADD CONSTRAINT FK_PROFAM_PorFormRem FOREIGN KEY (Id_Form_Rem)
	REFERENCES Tab_Formularios_Tipos (Id_Form)

IF NOT EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS  WHERE CONSTRAINT_NAME='FK_PROFAM_PorFormFac' )
ALTER TABLE Prod_Familias ADD CONSTRAINT FK_PROFAM_PorFormFac FOREIGN KEY (Id_Form_Fac)
	REFERENCES Tab_Formularios_Tipos (Id_Form)



