在SQLServer上查看SQL語句的執(zhí)行時間的方法
發(fā)布日期:2022-01-29 12:45 | 文章來源:CSDN
1:下面這種是比較簡單的查詢方法,通過查詢前的時間和查詢后的時間差來計算的
復(fù)制代碼 代碼如下:
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:下面這種方法比較全面,將執(zhí)行每個語句時采取的步驟作為行集返回,通過層次結(jié)構(gòu)樹的形式展示出來
復(fù)制代碼 代碼如下:
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語句執(zhí)行的時間有多長。下面是其中一種辦法。
declare @preDate Datetime select @preDate = getdate() print @preDate select datepart(ms,@preDate) as ms, datepart(ss,@preDate) as second,datepart(mi,@preDate) as minute go --需要測試的SQL語句 go declare @preDate Datetime SELECT @preDate= getdate() select datepart(ms,@preDate) as ms, datepart(ss,@preDate) as second,datepart(mi,@preDate) as minute
這樣可以知道你的語句到底運行了多少毫秒。
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章