IF NOT EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Listas_Precios_Tar' AND xtype='U')
BEGIN
	CREATE TABLE Prod_Listas_Precios_Tar 
	(
		Id_Lista_Precio_Tar				INT IDENTITY(1,1),
		Id_Lista_Precio					SMALLINT,
		Id_Tarjeta						VARCHAR(10),
		Activo							TINYINT
		CONSTRAINT PK_PLPT_PorId PRIMARY KEY CLUSTERED (Id_Lista_Precio_Tar)	
	)
	
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Listas_Precios_Tar' AND xtype='U')
	AND  NOT EXISTS (SELECT * FROM sysindexes WHERE NAME = 'IX_PLPT_PorLista')
BEGIN
	CREATE INDEX IX_PLPT_PorLista ON Prod_Listas_Precios_Tar (Id_Lista_Precio)
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Listas_Precios_Tar' AND xtype='U')
	AND  NOT EXISTS (SELECT * FROM sysindexes WHERE NAME = 'IX_PLPT_PorTar')
BEGIN
	CREATE INDEX IX_PLPT_PorTar ON Prod_Listas_Precios_Tar (Id_Tarjeta)
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Listas_Precios_Tar' AND xtype='U')
	AND NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'FOREIGN KEY' 
	AND CONSTRAINT_NAME = 'FK_PLPT_Lista')
BEGIN
	ALTER TABLE Prod_Listas_Precios_Tar  ADD CONSTRAINT FK_PLPT_Lista FOREIGN KEY(Id_Lista_Precio)
	REFERENCES Prod_Listas_Precios (Id_Lista_Precio)
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE Name='Prod_Listas_Precios_Tar' AND xtype='U')
	AND NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'FOREIGN KEY' 
	AND CONSTRAINT_NAME = 'FK_PLPT_Tarjetas')
BEGIN
	ALTER TABLE Prod_Listas_Precios_Tar  ADD CONSTRAINT FK_PLPT_Tarjetas FOREIGN KEY(Id_Tarjeta)
	REFERENCES Valores_Tarjetas_Cred (Id_Tarjeta)
END
GO