renshanshan 发表于 2016-10-22 07:21:03

MySQL使用LAST_INSERT_ID()获取新插入记录的ID

0
<script language="javascript" type="text/javascript" src="http://static.bshare.cn/b/buttonLite.js#style=-1&amp;uuid=23a3475a-b05e-4ee9-bea7-b3336a11ccf6&amp;pophcol=2&amp;lang=zh"></script><script language="javascript" type="text/javascript" src="http://static.bshare.cn/b/bshareC2.js"></script>  

  MySQL:
  
delimiter //CREATE PROCEDURE P__Test_Insert(out nUserId int,in strAlias varchar(100),in strPwd varchar(100))Beginif not exists(select * from _User where UserName = strAlias) theninsert into _User(UserName, PassWord, CreateTime) values(strAlias, strPwd, now());set nUserId = LAST_INSERT_ID();end if;End

  
  前提:ID字段需设置为AUTO_INCREMENT。
页: [1]
查看完整版本: MySQL使用LAST_INSERT_ID()获取新插入记录的ID