Después de tanto intentar, he aquí mi resultado:
CREATE TABLE linea_estaciones
(
id
BIGINT (20),
linea_id
BIGINT (20) NOT NULL,
estacion_id
BIGINT (20),
create_at
TIMESTAMP,
update_at
TIMESTAMP,
PRIMARY KEY (id)
CONSTRAINT linea_estaciones_linea_id_foreign
FOREIGN KEY (linea_id
) REFERENCES linea
(id
),
CONSTRAINT linea_estaciones_estacion_id_foreign
FOREIGN KEY (estacion_id
) REFERENCES estaciones
(id
)
);
INSERT INTO linea_estaciones
(id
, linea_id
, estacion_id
) VALUES
(1, 1, 2),
(2, 1, 11),
(3, 1, 8),
(4, 1, 5),
(5, 1, 4),
(6, 2, 3),
(7, 2, 1),
(8, 2, 7),
(9, 2, 10),
(10, 2, 14),
(11, 3, 6),
(12, 3, 9),
(13, 3, 13),
(14, 3, 15),
(15, 3, 12);
INSERT INTO linea_estaciones
(linea_id
, estacion_id
) VALUES
(
5,
(
SELECT lineas
.id
FROM lineas
WHERE lineas
.nombre
= “Linea 1”
),
(
SELECT estaciones
.id
FROM estaciones
WHERE estaciones
.nombre
= “Estacion 2”
)
);
Want to see more contributions, questions and answers from the community?