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

0


MySQL:

delimiter //
CREATE PROCEDURE P__Test_Insert(

    out nUserId int,
    in strAlias varchar(100),
    in strPwd varchar(100)
)
Begin	
    if not exists(select * from _User where UserName = strAlias) then
        insert into _User(UserName, PassWord, CreateTime) values(strAlias, strPwd, now());
        set nUserId = LAST_INSERT_ID();
    end if;
End


前提:ID字段需设置为AUTO_INCREMENT。


你可能感兴趣的:(MySQL,LAMP开发与应用)