MySQL使用LAST_INSERT_ID()获取新插入记录的ID
0<script language="javascript" type="text/javascript" src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=23a3475a-b05e-4ee9-bea7-b3336a11ccf6&pophcol=2&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]