Environment, amt, toaccno, fromaccno)
Environment: MySQL Sever 5.1 MySQL command line tool first let's take a look at an example (the primary key is auto-incrementing): mysql insert into bankaccount (name, balance) values ('123', 123); Query OK, 1 row affected (0.06 sec) mysql insert into bankstatement (action, txdate, amt, toaccno, fromaccno)
Environment: MySQL Sever 5.1 + MySQL command line tool
First, let's look at an example (the primary key is auto-incrementing ):
Mysql> insert into bankaccount (name, balance) values ('000000', 123); Query OK, 1 row affected (1000 sec) mysql> insert into bankstatement (action, txdate, amt, toaccno, fromaccno) values ('201312', curdate (), 122, 1, 2); Query OK, 1 row affected (1000 sec) mysql> select last_insert_id (); + ------------------ + | last_insert_id () | + -------------------- + | 7 | + ------------------ + 1 row in set (0.00 sec) mysql> select * from bankaccount; + ------- + ------ + --------- + | accno | name | balance | + ------- + ------ + --------- + | 1 | Zhang San | 200 | 2 | Li Si | 900 | 3 | 123 | 1000 | 4 | 123 | 1000 | + ------- + ------ + --------- + 4 rows in set (0.00 sec) mysql> select * from bankstatement; + ---- + -------------- + ------------ + ------ + --------- + ----------- + | id | action | txdate | amt | toaccno | fromaccno | + ---- + -------------- + ------------ + ------ + ----------- + 1 | account opening | 100 | NULL | 1 | 2 | account opening | 2012-10-14 | 1000 | NULL | 2 | 3 | query account information | 2012-10-14 | 0 | NULL | 2 | | 4 | search for account information | 2012-10-14 | 0 | NULL | 1 | 5 | transfer | 2012-10-14 | 100 | 1 | 2 | 6 | 122 | 2012-10-14 | 1000 | 1 | 2 | 7 | 122 | 2012-10-14 | 1000 | 1 | 2 | + ---- + ---------------- + ---------- + ------ + --------- + ----------- + 7 rows in set (0.00 sec)
Conclusion: LAST_INSERT_ID () returns the value of the AUTO_INCREMENT column in The Last INSERT or UPDATE statement.
References:
Http://zhaohe162.blog.163.com/blog/static/38216797201122411193745/
Http://it.100xuexi.com/view/otdetail/20120619/73a6cc8f-36b8-4b70-8904-57c18d3ab385.html
Http://blog.csdn.net/wh62592855/article/details/6722298