SQL查询执行时间 [英] SQL query execution time

查看:338
本文介绍了SQL查询执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取文本文件中sql查询的执行时间?

How to get execution time of a sql query in a text file?

推荐答案

TimeSpan Duration; 
DateTime StartTime = DateTime.Now
'Call the database here and execute your SQL statement
Duration = DateTime.Now.Subtract(StartTime)
Console.WriteLine(String.Format("Query took {0} seconds", Duration.TotalSeconds.ToString()))
Console.ReadLine()



如果有帮助,请 投票 接受答案 .



Please vote and Accept Answer if it Helped.


首先,我想请您清楚地发表问题.记录执行时间的目的是什么?是由应用程序记录以保持日志,还是要检查一些运行缓慢的查询的性能和执行时间.

假设您需要它来检查性能,我建议您使用SQL Profiler,这样您将获得详细的执行计划. Showplan将使您获得所需的结果.
Firstly, I would ask you to post the question bit clearly. What is the purpose of recording the execution time? Is it to be recorded by the application to keep log or do you want to check the performance and execution time of few slow running queries.

Assuming, you need it to check the performance, I would suggest you to use SQL Profiler, with that you would get detailed execution plan. Showplan will allow you to get the desired result.


这篇关于SQL查询执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆