IF EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Familias_Garantias' AND Xtype='U')
BEGIN
	DROP TABLE Prod_Familias_Garantias
END
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Familias_Garantias' AND Xtype='U')
BEGIN
	CREATE TABLE Prod_Familias_Garantias (
			Id_Familia_Garan  	INT IDENTITY(1,1) NOT NULL,
			Id_Familia			INT NOT NULL,
			Meses_Garantia		SMALLINT,
			Descripcion			VARCHAR(255),
			Coef				DECIMAL(8,5),
			Id_Producto			VARCHAR(14),
			CONSTRAINT PK_PFG_PorID PRIMARY KEY (Id_Familia_Garan)
			)

	CREATE INDEX IX_PFG_PorFam ON Prod_Familias_Garantias (Id_Familia,Meses_Garantia)

	CREATE INDEX IX_PFG_PorProdGran ON Prod_Familias_Garantias (Id_Producto)

	ALTER TABLE Prod_Familias_Garantias ADD CONSTRAINT FK_PFG_Prod_Familias FOREIGN KEY (Id_Familia)
		REFERENCES Prod_Familias (Id_Familia)

	ALTER TABLE Prod_Familias_Garantias ADD CONSTRAINT FK_PFG_Productos FOREIGN KEY (Id_Producto)
		REFERENCES Productos (Id_Producto)
END
GO
