數(shù)據(jù)庫:計(jì)算SQL語句執(zhí)行時(shí)間的方法

字號(hào):

一、按照BAIDU.GOOGLE及CSDN等搜索結(jié)果
    在SQL語句前面加上了這一句:
    經(jīng)查詢,SET STATISTICS TIME ON命令報(bào)告下面的查詢的實(shí)際占用時(shí)間和CPU使用情況。
    使用后覺得給出的時(shí)間很細(xì)致,跟執(zhí)行過程結(jié)合的很緊密,但是比較多,似乎不夠精確。
    二、CNBLOGS網(wǎng)友的文章里
    Code
    use northwind
    declare @date1 datetime
    declare @date2 datetime
    select @date1=getdate()
    --測試語句
    select * from employees
    select @date2=getdate()
    select datediff(millisecond, @date1, @date2)
    --結(jié)果是毫秒數(shù)
    方法簡單易懂。使用起來也很方便。
    Code
    set statistics time on