如何查看SQL语句的执行时间

2024-12-17 13:56:12
推荐回答(1个)
回答1:

declare @sttime datetime
set @sttime=getdate()
print @sttime
Select * from case1219 -- 把你的sql语句放在这里
SELECT RTRIM(CAST(DATEDIFF(MS, @sttime, GETDATE()) AS CHAR(10))) AS 'TimeTaken'

或者这么写

DECLARE @t1 DATETIME;
DECLARE @t2 DATETIME;
SET @t1 = GETDATE();
Select * from dimDate ;-- 把你要查询的sql语句放在这里
SET @t2 = GETDATE();
SELECT DATEDIFF(millisecond,@t1,@t2) AS elapsed_ms;