- Tabla "Película_que_tiene_el_cliente" (Está relacionado con la tabla "Clientes").
Yo la llamaría
Películas Alquiladas. Tambien debes poner a quien se la alquilas, no?
- Tabla "Clientes_con_copias_de_estas_películas".
No acabo de entender que tipo de información vas a almacenar en esta tabla.
En la tabla
Clientes puedes usar como clave primaria tanto el
DNI (es único por persona) o usar un ID proprio.
Puedes hacer algo así:
Claramente se puede optimizar/modificar mucho mas, pero al menos puedes hacerte una idea de como hacer las relaciones.
Por si lo quieres, te dejo el script sql para hacer la base de datos como yo lo he hecho.
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
CREATE SCHEMA IF NOT EXISTS `Videoclub` DEFAULT CHARACTER SET utf8 COLLATE utf8_spanish_ci ;
USE `Videoclub` ;
-- -----------------------------------------------------
-- Table `Videoclub`.`clientes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Videoclub`.`clientes` (
`idcliente` INT NOT NULL AUTO_INCREMENT ,
`DNI` VARCHAR(45) NOT NULL ,
`Nombre` VARCHAR(45) NULL ,
`Apellidos` VARCHAR(45) NULL ,
`Direccion` VARCHAR(45) NULL ,
`Fecha_Nacimiento` VARCHAR(45) NULL ,
`Email` VARCHAR(45) NULL ,
`Tel_Fijo` INT NULL ,
`Tel_Movil` INT NULL ,
`Observaciones` VARCHAR(60) NULL ,
PRIMARY KEY (`idcliente`, `DNI`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Videoclub`.`peliculas_alquiladas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Videoclub`.`peliculas_alquiladas` (
`idpelicula_alquilada` INT NOT NULL AUTO_INCREMENT ,
`id_pelicula` INT NULL ,
`Titulo` VARCHAR(45) NULL ,
`ClienteID` INT NULL ,
`Fecha_Devolucion` DATETIME NULL ,
`Dias_Retraso` DATETIME NULL ,
`clientes_idcliente` INT NOT NULL ,
`clientes_DNI` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`idpelicula_alquilada`, `clientes_idcliente`, `clientes_DNI`) ,
INDEX `fk_peliculas_alquiladas_clientes1` (`clientes_idcliente` ASC, `clientes_DNI` ASC) ,
CONSTRAINT `fk_peliculas_alquiladas_clientes1`
FOREIGN KEY (`clientes_idcliente` , `clientes_DNI` )
REFERENCES `Videoclub`.`clientes` (`idcliente` , `DNI` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Videoclub`.`peliculas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Videoclub`.`peliculas` (
`idpelicula` INT NOT NULL ,
`Titulo` VARCHAR(45) NULL ,
`Genero` VARCHAR(45) NULL ,
`Duracion` VARCHAR(45) NULL ,
`Copias` VARCHAR(45) NULL ,
`Disponibles` VARCHAR(45) NULL ,
`Precio` VARCHAR(45) NULL ,
`Formato` INT NULL ,
`año` VARCHAR(45) NULL ,
`Actor_Principal` VARCHAR(45) NULL ,
`Director` VARCHAR(45) NULL ,
`Descripcion` VARCHAR(45) NULL ,
`Notas` VARCHAR(45) NULL ,
`peliculas_alquiladas_idpelicula_alquilada` INT NOT NULL ,
PRIMARY KEY (`idpelicula`, `peliculas_alquiladas_idpelicula_alquilada`) ,
INDEX `fk_peliculas_peliculas_alquiladas1` (`peliculas_alquiladas_idpelicula_alquilada` ASC) ,
CONSTRAINT `fk_peliculas_peliculas_alquiladas1`
FOREIGN KEY (`peliculas_alquiladas_idpelicula_alquilada` )
REFERENCES `Videoclub`.`peliculas_alquiladas` (`idpelicula_alquilada` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `Videoclub`.`formatos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Videoclub`.`formatos` (
`idformato` INT NOT NULL AUTO_INCREMENT ,
`nombre` VARCHAR(45) NULL ,
`peliculas_idpelicula` INT NOT NULL ,
PRIMARY KEY (`idformato`, `peliculas_idpelicula`) ,
INDEX `fk_formatos_peliculas` (`peliculas_idpelicula` ASC) ,
CONSTRAINT `fk_formatos_peliculas`
FOREIGN KEY (`peliculas_idpelicula` )
REFERENCES `Videoclub`.`peliculas` (`idpelicula` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Repito, puedes modificar mucho mas la DB.