gpt4 book ai didi

tsql - 如果@@rowcount>0 将@@rowcount 重置为0,则执行。为什么?

转载 作者:行者123 更新时间:2023-12-04 02:06:03 26 4
gpt4 key购买 nike

Link

@@Rowcount is used to inform the number of rows affected for the last select,insert,update or delete statements

declare @row int select 100 if @@rowcount>0  set @row=@@rowcount ...

The above will return 0 because as soon as if @@rowcount>0 is executed it is reset to 0 as it doesn't return any rows. So always assign to variable first



为什么声明 if @@rowcount>0重置 @@rowcount到 0?不是 @@rowcount的值吗?仅受选择、插入、更新和删除语句的影响?

谢谢

最佳答案

它受最后一条语句的影响。像这个 SET 语句

Declare @row int
select 100 union all select 200 union all select 300
set @row = @@rowcount;
SELECT @row, @@rowcount

如果您阅读了 actual Microsoft SQL Server Docs on MSDN ,它举例说明了哪些语句会影响 @@ROWCOUNT .例如,“例如”意味着其他语句如 IF 也会将其设置为零

Statements such as USE, SET <option>, DEALLOCATE CURSOR, CLOSE CURSOR, BEGIN TRANSACTION or COMMIT TRANSACTION reset the ROWCOUNT value to 0.

关于tsql - 如果@@rowcount>0 将@@rowcount 重置为0,则执行。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7705509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com