IF ( ISNULL((SELECT COUNT(*) FROM Prod_Fotos),0)) < 3 
BEGIN 
	DROP TABLE Prod_Fotos


	CREATE TABLE [dbo].[Prod_Fotos](
		[Id_Producto_Foto] [INT] IDENTITY(1,1) NOT NULL,
		[Id_Producto] [VARCHAR](14) NOT NULL,
		[Orden] [SMALLINT] NULL,
		[Foto] [IMAGE] NULL,
		[Fecha] [DATETIME] NULL,
		[Flag_Vta_Web] [tinyint] NULL,
		 CONSTRAINT [PK_PFOT_PorId] PRIMARY KEY CLUSTERED 
			(
				[Id_Producto_Foto] ASC
			)
	)
	CREATE UNIQUE INDEX  IF_PFOT_PorID ON  [Prod_Fotos]  ([Id_Producto],[Orden])

	ALTER TABLE [dbo].[Prod_Fotos]  ADD  CONSTRAINT [FK_PFOT_Productos] FOREIGN KEY([Id_Producto])
	REFERENCES [dbo].[Productos] ([Id_Producto])

END
GO



