确定存储过程触发了多少个循环

发布于 2024-12-13 05:42:00 字数 147 浏览 0 评论 0原文

我在 SQL Server 2008 R2 上创建了一个稍微复杂的存储过程,这个 SP 还包含一些用户定义的函数。这些 UDF 和 SP 本身内部有一些 while 循环。

我想确定当我调用此 SP 时某些内容已循环了多少次。

我可以做任何改变吗?

I have created a little complex stored procedure on SQL Server 2008 R2 and this SP also contains some user defined functions. Those UDFs and the SP itself has some while loops inside them.

I would like determine how many times something has been looped when I call this SP.

Any change I can do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-12-20 05:42:00

据我所知,SQL Profiler 没有任何方法可以做到这一点。我要做的是创建一个临时表(假设您只对单个连接的迭代次数感兴趣)来增加单个计数变量,然后您可以输出最后存储在该临时表中的值循环的。

例如:

create table #countTable
(
    id int not null,
    countvar int not null
)
go

insert into #countTable
select 1, 0
go

-- your stored proc call here
--   during your iterations at the end, call this:
update #countTable
set countvar = countvar + 1
where id = 1
go

-- ...your stored proc ends now you want the count
select countvar
from #countTable
where id = 1
go

我创建了一个 id 字段,以防您可能需要多个“计数器”。

SQL Profiler doesn't have any way to do this, as far as I know. What I'd do is create a temporary table (provided you are only interested in the number of iterations for a single connection) to increment the single count variable, and then you can output the value that is stored in that temp table at the end of the loop.

Something like:

create table #countTable
(
    id int not null,
    countvar int not null
)
go

insert into #countTable
select 1, 0
go

-- your stored proc call here
--   during your iterations at the end, call this:
update #countTable
set countvar = countvar + 1
where id = 1
go

-- ...your stored proc ends now you want the count
select countvar
from #countTable
where id = 1
go

I made an id field in case there is more than one "counter" you may want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文