获取上次更新的行 [英] Getting last updated row
本文介绍了获取上次更新的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在表中执行更新查询,我必须返回更新的那一行的ID.如何获得该信息.如果我使用IDENT_CURRENT(''tbl''),它将返回最后一个ID.该表,所以我不能使用它...任何人都可以帮我吗
I am executing an update query in a table and i have to return the ID of that row i updated.. How can i get that.. IF i use IDENT_CURRENT(''tbl'') it returns the last id of that table , so i can''t use that...Can anyone pls help me
推荐答案
您需要在表中添加日期字段并添加触发器更新它.
You need to add a date field to the table and add a trigger to update it.
CREATE TRIGGER LastChangedOnTbl on Tbl
FOR UPDATE, INSERT AS
UPDATE dbo.Tbl
SET LastUpdate = GetDate()
WHERE id IN (SELECT id FROM inserted)
然后,您可以使用此字段选择最近更新的行.
祝你好运!
You can then use this field to select the most recently updated row.
Good luck!
这篇关于获取上次更新的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文