且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mySQL:将值插入具有外键关系的2个表中

更新时间:2023-01-20 13:49:30

首先插入员工.

INSERT INTO mitarbeiter
            (maanrede,
             ...)
            VALUES(?,
                   ...);

然后插入SIM卡.使用 last_insert_id() 获取为员工记录创建的ID.

Then insert the SIM card. Use last_insert_id() to get the ID created for the employee record.

INSERT INTO mobilfunkkarten
            (mfktarif,
             ...,
             maID)
            VALUES (?,
                    ...,
                    last_insert_id());