Given these tables:
create table country
(
country_id integer primary key auto_increment,
name varchar(16) unique not null
);
insert into country(name) values
('USA'),
('Canada');
create table network
(
network_id integer primary key auto_increment,
name varchar(32) not null,
country_id integer references country(country_id)
on cascade update
on delete restrict
);
I want to perform an insert into network(country_id, name) values where name is a list of values, but country_id is the same for each row, the result of a subquery that’s something like select country_id from country where name = 'Canada'. I want to do this all in one insert, not an insert with an update afterwards. I think it calls for a join but I’m not sure.
Ideas?
Sidekick: Do not define Foreign Keys inline in MysQL, they are ignored:
Define them after the list of columns, separately. I prefer to define Primary Key constraints as well after the columns: