有什么方法可以获取上次更新的行 ID

发布于 2024-08-03 06:07:29 字数 126 浏览 2 评论 0原文

有什么方法可以获取我更新的表的最后一行。

例如:- 我的表中有 1000 条记录。 我已经更新了表 X 的第 500 条记录的值。 所以,我想要 ID 500 作为回报。

提前致谢。

问候,

Is there any way using which I can get the last row I have updated of the table.

For Ex:- my table has 1000 records in it.
I have updated the value of 500th record of table X.
So, I want the ID 500 in return.

Thanks in advance.

Regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2024-08-10 06:07:29

我认为 MySQL 不存在这个功能。但是,您可以通过添加时间戳列来获得相同的效果:

ALTER TABLE yourtable
   ADD COLUMN last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

这将使 last_update 列几乎自动维护。现在,您可以根据时间戳从表中选择最后更新的行。

I don't think this feature exists with MySQL. However you can get the same effect by adding a timestamp column:

ALTER TABLE yourtable
   ADD COLUMN last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

This would make the last_update column pretty much automatically maintained. Now you can select from yourtable the last updated row based on the timestamp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文