Calculate execution time of a SQL query?

前端 未结 8 431
悲&欢浪女
悲&欢浪女 2020-12-04 14:17

I am providing search functionality in my website, when user searches a record then I want to display the time the query taken to get the results same as google does. When w

8条回答
  •  情话喂你
    2020-12-04 14:47

    try this

    DECLARE @StartTime DATETIME
    SET @StartTime = GETDATE()
    
      SET @EndTime = GETDATE()
      PRINT 'StartTime = ' + CONVERT(VARCHAR(30),@StartTime,121)
      PRINT '  EndTime = ' + CONVERT(VARCHAR(30),@EndTime,121)
      PRINT ' Duration = ' + CONVERT(VARCHAR(30),@EndTime -@starttime,114)
    

    If that doesn't do it, then try SET STATISTICS TIME ON

提交回复
热议问题