[Php-avanzado] BD tesis Carrito de compras

Leonardo Tadei - Pegasus Tech Supply leonardot en pegasusnet.com.ar
Sab Dic 13 21:38:25 ART 2008


Hola Mauro,

El sáb, 13-12-2008 a las 11:17 -0300, Mauro Giuffo escribió:
> Hola Leo :
> 
> te mando la estructura de la base de datos para la tesis Carrito de
> compras. 

	Ok. Comentarios abajo.

> Todavia no me quedo claro como armar la tabla del detalle de los
> pedidos, ya que los articulos pueden desaparecer segun la lista que
> llegue del sistema externo que la genera.

	Es que la información del código, descripción y precios debe estar
también en la tabla de detalles de pedido.
	Notaste el punto: esos datos pueden cambiar.

	La justificación es que esto no es una repetición, sino almacenar la
realidad de "ese momento" para recuperarla más tarde.

> ----------------------------------------------------------------
> 
> /*
> Created 13/12/2008
> Modified 13/12/2008
> Project  
> Model  
> Company  
> Author  
> Version  
> Database mySQL 5 
> */
> 
> 
> Create table tipos_usuario (
>  id Int UNSIGNED NOT NULL AUTO_INCREMENT,
>  nombre Varchar(20) NOT NULL,
>  UNIQUE (nombre),
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table usuarios (
>  id Int UNSIGNED NOT NULL AUTO_INCREMENT,
>  id_tipo Int UNSIGNED NOT NULL,
>  nombre Varchar(20) NOT NULL,
>  password Varchar(20) NOT NULL,
>  email Varchar(60) NOT NULL,
>  UNIQUE (nombre),
>  UNIQUE (email),
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table articulos (
>  id Int UNSIGNED NOT NULL AUTO_INCREMENT,
>  id_familia Char(20) UNSIGNED NOT NULL,
>  id_marca Char(20) UNSIGNED NOT NULL,
>  id_grupo Char(20) UNSIGNED NOT NULL,
>  codigo Varchar(20) NOT NULL,
>  descripcion Varchar(60) NOT NULL,
>  precio Decimal(10,3) NOT NULL,
>  UNIQUE (codigo),
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table familias (
>  id Char(20) UNSIGNED NOT NULL AUTO_INCREMENT,
>  descripcion Varchar(60) NOT NULL,
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table marcas (
>  id Char(20) UNSIGNED NOT NULL AUTO_INCREMENT,
>  descripcion Varchar(60) NOT NULL,
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table grupos (
>  id Char(20) UNSIGNED NOT NULL AUTO_INCREMENT,
>  descripcion Varchar(60) NOT NULL,
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table pedidos (
>  id Int UNSIGNED NOT NULL AUTO_INCREMENT,
>  id_estado Int UNSIGNED NOT NULL,
>  id_usuario Int UNSIGNED NOT NULL,
>  fecha Date NOT NULL,
>  Primary Key (id)) ENGINE = MyISAM;

	Por lo mismo, deberías acá guardar el nombre del usuario y no una
referencia a él.

> Create table estados (
>  id Int UNSIGNED NOT NULL AUTO_INCREMENT,
>  nombre Varchar(20) NOT NULL,
>  UNIQUE (nombre),
>  Primary Key (id)) ENGINE = MyISAM;
> 
> Create table pedidos_det (
>  id_pedido Int UNSIGNED NOT NULL,
>  id_articulo Int UNSIGNED NOT NULL,
>  codigo Varchar(20) NOT NULL,
>  descripcion Varchar(60) NOT NULL,
>  precio Decimal(10,3) NOT NULL,
>  cantidad Int NOT NULL,
>  Primary Key (id_pedido,id_articulo)) ENGINE = MyISAM;

	Esto es correcto por lo expresado al principio.

> Alter table usuarios add Foreign Key (id_tipo) references
> tipos_usuario (id) on delete restrict on update restrict;
> Alter table pedidos add Foreign Key (id_usuario) references usuarios
> (id) on delete restrict on update restrict;
> Alter table pedidos_det add Foreign Key (id_articulo) references
> articulos (id) on delete restrict on update restrict;
> Alter table articulos add Foreign Key (id_familia) references familias
> (id) on delete restrict on update restrict;
> Alter table articulos add Foreign Key (id_marca) references marcas
> (id) on delete restrict on update restrict;
> Alter table articulos add Foreign Key (id_grupo) references grupos
> (id) on delete restrict on update restrict;
> Alter table pedidos_det add Foreign Key (id_pedido) references pedidos
> (id) on delete restrict on update restrict;
> Alter table pedidos add Foreign Key (id_estado) references estados
> (id) on delete restrict on update restrict;

	Con qué generás esto que te guarda los alter table???

	Controlar la integridad con claves foráneas no te salvará de validar
las entradas en JS y en PHP ;-)

> Saludos

	=mente!
-- 
Leonardo Tadei
leonardot en pegasusnet.com.ar
http://blog.pegasusnet.com.ar
Firma pública: http://www.pegasusnet.com.ar/LeonardoTadei-public.key



Más información sobre la lista de distribución Php-avanzado