Seperti yang Anda sarankan, Anda dapat menggunakan klausa OUTPUT secara efektif:
Demo langsung:https://data.stackexchange.com/stackoverflow/query/8058/ jadi3319842
UPDATE #tbl
SET locked = 1
OUTPUT INSERTED.*
WHERE id IN (
SELECT TOP 1 id
FROM #tbl
WHERE locked = 0
ORDER BY id
)
Lihat juga artikel ini:
http ://www.sqlmag.com/article/tsql3/more-top-troubles-using-top-with-insert-update-and-delete.aspx