Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/02/2008, 15:08
perris
 
Fecha de Ingreso: enero-2008
Mensajes: 73
Antigüedad: 16 años, 4 meses
Puntos: 0
Re: foreign key en phpMyAdmin

espero que te sirva este codigo ten en cuenta que para que puedas usar integridad referencial tienes que habilitar en la instalacion de appserver la opcion innodb.

hay una herramienta para hacer estas relaciones graficamente se llama dbdesigner 4. DIOS LOS BENDIGA

Código:
CREATE TABLE producto_terminado (
  Cod_Producto CHAR NOT NULL,
  Cod_Linea INT UNSIGNED NOT NULL,
  Nombre_Producto CHAR NOT NULL,
  Descripcion_Producto CHAR NOT NULL,
  Cantidad_Existente INT UNSIGNED NOT NULL,
  Tipo_producto CHAR NOT NULL,
  Precio_Unitario INT UNSIGNED NOT NULL,
  PRIMARY KEY(Cod_Producto),
  INDEX producto_terminado_FKIndex1(Cod_Linea),
  FOREIGN KEY(Cod_Linea)
    REFERENCES linea_o_categoria(Cod_Linea)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION
)
TYPE=InnoDB;

CREATE TABLE linea_o_categoria (
  Cod_Linea INT UNSIGNED NOT NULL,
  Nombre_Linea CHAR NOT NULL,
  PRIMARY KEY(Cod_Linea)
)
TYPE=InnoDB;