存储过程如何返回 ROWCOUNT?
我编写了存储过程,其中有 2 个插入查询和 1 个更新查询。其中,插入查询或更新查询都是同时执行的。现在我的问题是在每种情况下获取ROWCOUNT
。假设如果执行插入操作,那么我希望存储过程将@@ROWCOUNT返回给调用应用程序,以便应用程序知道所需的操作是否正确执行。谁能建议/告诉我如何获取存储过程影响的行?
I have written stored procedure which has 2 Insert queries and 1 Update query inside it. Of all these,either insert queries or update query are executed at a time. Now my problem is to get ROWCOUNT
in each case. Say suppose if insert operations are executed,then I want stored procedure to return @@ROWCOUNT
to the calling application, so that the application will be aware of whether the required operations executed correctly or not. Can anyone suggest/tell me how can I get the rows affected from the stored procedure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在存储过程中使用输出参数返回插入/更新的 RowCount。
有关如何使用输出参数的详细信息,请参阅 MSDN 链接
您可以有多个输出参数,因此您可以有 2 个不同的输出参数,每个参数用于插入,第三个用于更新语句。
示例:
此外,您始终可以使用分隔符连接 2 个插入/更新的行计数,并将它们作为一个值返回,例如:“10;0” - 然而这是老式的“我不推荐”方法。
此外,您还可以创建一个表变量并返回表,其中行数 = 插入/更新数,列的值 = 受影响的 RowCount。
Use Output parameters in your stored procedures to return the RowCount of your inserts / updates.
Refer MSDN link for more information on how to use Output params
You can have multiple output params so you can have 2 different output params one each for your insert and the 3rd for your update statement.
Example:
Additionally, you can always concatenate the rowcounts of your 2 Inserts / Update using delimiters and return them as one value eg: "10;0" - However that is the old fashioned and "I would not recommend" approach.
Also, you could create a table variable and return the table with rows = number of Inserts / updates and the value of the column = RowCount affected.