@@ -44,7 +44,7 @@ create table pelicula (
44
44
id serial primary key ,
45
45
titulo varchar (80 ) not null ,
46
46
id_genero integer not null ,
47
- director varchar ( 80 ) not null ,
47
+ id_director integer not null ,
48
48
sinopsis text
49
49
);
50
50
@@ -53,6 +53,11 @@ create table genero (
53
53
genero varchar (50 ) not null
54
54
);
55
55
56
+ create table director (
57
+ id serial primary key ,
58
+ nombre varchar (80 ) not null
59
+ );
60
+
56
61
alter table direccion
57
62
add constraint direccion_socio_fk
58
63
foreign key (num_socio)
@@ -78,6 +83,11 @@ add constraint pelicula_genero_fk
78
83
foreign key (id_genero)
79
84
references genero (id);
80
85
86
+ alter table pelicula
87
+ add constraint pelicula_director_fk
88
+ foreign key (id_director)
89
+ references director (id);
90
+
81
91
-- Inicio la inserción de datos en una tabla auxiliar:
82
92
CREATE TABLE tmp_videoclub (
83
93
id_copia int4 NULL ,
@@ -639,10 +649,16 @@ select distinct genero from tmp_videoclub;
639
649
640
650
create unique index genero_sin_repetir on genero (lower (genero));
641
651
642
- insert into pelicula (titulo, id_genero, director, sinopsis)
643
- select distinct titulo, g .id , director, sinopsis
652
+ insert into director (nombre)
653
+ select distinct director from tmp_videoclub;
654
+
655
+ create unique index director_sin_repetir on director (lower (nombre));
656
+
657
+ insert into pelicula (titulo, id_genero, id_director, sinopsis)
658
+ select distinct titulo, g .id , d .id , t .sinopsis
644
659
from tmp_videoclub t
645
- inner join genero g on g .genero = t .genero ;
660
+ inner join genero g on g .genero = t .genero
661
+ inner join director d on d .nombre = t .director ;
646
662
647
663
create unique index titulo_sin_repetir on pelicula (lower (titulo));
648
664
@@ -666,8 +682,3 @@ inner join pelicula on pelicula.id = copia.id_pelicula where no_disp.id is null
666
682
667
683
668
684
669
-
670
-
671
-
672
-
673
-
0 commit comments