Tema: relacion n:m
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 29/03/2011, 08:11
jvcano
 
Fecha de Ingreso: marzo-2011
Mensajes: 17
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: relacion n:m

Si te he entendido bien, lo que necesitas es algo parecido a esto (la definicion de los campos no la pongo, para que uses la que tienes actualmente) :

Create Table `LIBRO`(
`IDLIBRO` Integer(9) Not Null AUTO_INCREMENT,
`NOMBRE` ,
`ALIAS` ,
`IMAGEN` ,
`SINOPSIS` ,
`VOLUMENES` ,
`FECHA_EDICION` ,
PRIMARY KEY (`IDLIBRO`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Create Table `EDITORIAL`(
`IDEDITORIAL` Integer(9) Not Null AUTO_INCREMENT,
`IDLIBRO` Integer(9),
`NOMBRE` ,
`ACRONIMO` ,
`ALIAS` ,
`PORTADA` ,
PRIMARY KEY (`IDEDITORIAL`)
KEY (`IDLIBRO`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Lo que he hecho es añadir en la tabla 'EDITORIAL' el identificador de la tabla 'LIBRO'.

De esta forma puedes:
  • Leer todos los libros que tienes (leyendo de la tabla LIBROS).
  • Leer todas las editoriales que tienes (leyendo de la tabla EDITORIAL).
  • Leer en que editoriales hay un determinado libro (leyendo de la tabla EDITORIAL mediante IDLIBRO).

Espero que te sirva.