mysql用变量存储插入的id

INSERT into a(value) values ('test');
#set @last_id = LAST_INSERT_ID();
set @last_id = (select max(id) from a);
INSERT INTO b (a_id, `value`) values (@last_id, 'aaaa');
INSERT INTO b (a_id, `value`) values (@last_id, 'tetete');

INSERT into a(value) values ('bbbtest');
set @last_id = (select max(id) from a);
INSERT INTO b (a_id, `value`) values (@last_id, 'aaaa');
INSERT INTO b (a_id, `value`) values (@last_id, 'tetete');

posted @ 2013-12-19 14:07  幻星宇  阅读(2083)  评论(0编辑  收藏  举报