SQL:更新一行,并与1查询返回的列值 [英] SQL: Update a row and returning a column value with 1 query
本文介绍了SQL:更新一行,并与1查询返回的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更新表中的一行,并从它那里得到一个列值。我可以做到这一点。
I need to update a row in a table, and get a column value from it. I can do this with
UPDATE Items SET Clicks = Clicks + 1 WHERE Id = @Id;
SELECT Name FROM Items WHERE Id = @Id
这会产生2计划/访问表。是不可能性在T-SQL来修改UPDATE语句,以更新和1计划返回名称列/只能访问?
This generates 2 plans/accesses to the table. Is possibile in T-SQL to modify the UPDATE statement in order to update and return the Name column with 1 plan/access only?
我使用C#,ADO.NET 的ExecuteScalar()
或的ExecuteReader()
的方法。
I'm using C#, ADO.NET ExecuteScalar()
or ExecuteReader()
methods.
推荐答案
您想要的输出条款
UPDATE Items SET Clicks = Clicks + 1
OUTPUT INSERTED.Name
WHERE Id = @Id
这篇关于SQL:更新一行,并与1查询返回的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文