如何在MySql中获取Inserted值Id? [英] How get Inserted value Id in MySql ?.

查看:1058
本文介绍了如何在MySql中获取Inserted值Id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在MYSQL中输入值ID。



我正在使用选择LAST_INSERT_ID()但它不能正常工作。可以为此提供任何其他解决方案。请帮助我。



谢谢和问候



Madhava Reddy。

Hi,

How to Get Inserted value Id in MYSQL.

I am using " select LAST_INSERT_ID() " But its not working Properly.Can u provide any other solution For this.Please Help me.

Thanks & Regards

Madhava Reddy.

推荐答案

当服务器自动生成id时,你 一定不能将它包含在插入查询中(我不确定当前版本的MySQL,但是对于旧版本,你可以提供0而不是完全省略它。)
When the id is auto-generated by the server, you must not include it in the insert query (I am not sure with current versions of MySQL, but with old versions, you could supply 0 instead of omitting it completely).


您好,您可以通过将最后插入的ID存储在变量中来尝试这样。



Hi you can try out like this by storing the last inserted id in a variable.

Insert into Tbl(id,name,sal)values(_id,_name,_sal); 
SET @last_inserted_id = LAST_INSERT_ID();
select id,name,sal from Tb1 where id=@last_inserted_id;





希望它有用。



Hope it would be useful.


Hai

你的问题不明确,在哪个应用程序你需要使用select查询? web或windows?

无论如何你都可以试试这个,当你要插入时你肯定会传递值(比如唯一的id,name ect)来插入查询,所以在session中传递那个唯一的id或名字(如果它是web)或公共变量(如果它是windows)并在Select查询中使用该会话或公共变量。



或者你在ur表中使用autoincrement并选择使用select query
Hai
ur question is not clear,in which application u need to use select query ? web or windows ?
anyway u can try this,when u going to insert definitely u pass the values(like unique id,name ect) to insert query,so pass that unique id or name in session(if it is web) or public variable(if it is windows) and use that session or public variable in Select query.

Or u use autoincrement in ur table and select last id from table using select query


这篇关于如何在MySql中获取Inserted值Id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆