将生成的密钥从一个 table 插入到第二个 table 中,在一个请求中批量处理

Insert generated key from one table into second table with batch in one request

有两个 table 字段 occupation_id 具有一对多的依赖(关于预订酒店房间的项目)。每个职业实体可以有多个预订房间。有没有办法在单个 sql 请求插入到第一个 table (职业)和几个批量插入到第二个 table(booked_rooms).

表格是:

Table: Occupations
occupation_id bigint (autoincrement)
user_id bigint
check_in_date date
check_out_date date
status text

Table: Booked_rooms
booked_room_id bigint (autoincrement)
occupation_id bigint
beds int
class_rate int

使用交易:

BEGIN;
INSERT INTO ...;
SELECT LAST_INSERT_ID();
INSERT INTO ...;
COMMIT;