知道刚刚增加的值
我们每个人都知道如何在 MySQL 中增加列:
update table set col = col + 1 where id = 15;
但是...是否有办法在不执行 SELECT 查询的情况下知道新值?
谢谢
We everybody know how to increment a column in MySQL:
update table set col = col + 1 where id = 15;
But ... is there anyway to know the new value WITHOUT doing a SELECT query ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知。
如果您考虑一下,由于 UPDATE 可能会影响多行,因此考虑数据库在 UPDATE 上下文中返回所有数据并不简单,也不一定有吸引力。
MySQL 文档还解决了“我可以在同一个子查询中执行 UPDATE 和 SELECT 操作吗”问题:
http://dev.mysql.com/doc/refman/5.5/en /update.html
可能对您有用的一种替代方法是依赖 SELECT..FOR UPDATE 方法:
http://dev.mysql.com/doc/refman/5.5/en/innodb-locking-reads.html
Not that I'm aware of.
If you think about it, since multiple rows could be affected by an UPDATE, it's not trivial nor necessarily attractive to think about the database returning all of that data in the context of an UPDATE.
The MySQL docs also address the "can I do UPDATE and SELECT in the same subquery" question:
http://dev.mysql.com/doc/refman/5.5/en/update.html
One alternative that may work for you is to rely on the SELECT..FOR UPDATE approach:
http://dev.mysql.com/doc/refman/5.5/en/innodb-locking-reads.html
试图理解你的问题。
摘自 Justin Swanhart 发表于 2004 年 7 月 29 日 5:32pm@Mysql UPDATE refman 。
也许这就是你想要实现的目标
然后你可以做
Trying to understand your question.
Taken from Posted by Justin Swanhart on July 29 2004 5:32pm@Mysql UPDATE refman.
Maybe this is what you trying to achieve for
You could then do