加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 数据库 > MsSql > 正文

在SQLServer上查看SQL语句的执行时间的方法

发布时间:2020-09-25 21:03:15 所属栏目:MsSql 来源:互联网
导读:查看SQL语句在SQL Server上的执行时间,方便大家监控语句的性能。写出更好的代码。

1:下面这种是比较简单的查询方法,通过查询前的时间和查询后的时间差来计算的


代码如下: declare @begin_date datetime
declare @end_date datetime
select @begin_date = getdate()
<这里写上你的语句...>
select @end_date = getdate()
select datediff(ms,@begin_date,@end_date) as '用时/毫秒'


2:下面这种方法比较全面,将执行每个语句时采取的步骤作为行集返回,通过层次结构树的形式展示出来

代码如下: set statistics profile on
set statistics io on
set statistics time on
go
<这里写上你的语句...>
go
set statistics profile off
set statistics io off
set statistics time off

有时候我们需要知道一段SQL语句执行的时间有多长。下面是其中一种办法。

go
--需要测试的SQL语句
go

declare @preDate Datetime
SELECT @preDate= getdate()
select datepart(ms,@preDate) as minute

这样可以知道你的语句到底运行了多少毫秒。

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读