Dzwebs.Net

撰写电脑技术杂文十余年

如何知道SQL语句的执行时间

Admin | 2010-2-23 9:38:42 | 被阅次数 | 7485

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  我们都知道,无论是开发软件还是网站,都涉及到数据库的读取、写入、更新、删除等操作。

  并且,使用不同的SQL语句代码,处理同样的事物,其执行效益是不一样的。

  那么,我们如何才能知道,哪条SQL语句执行了多少时间,从而确定哪条语句的执行效益是最高的,进而最大限度的优化我们的SQL语句?

  方法代码如下,我们可以在查询中使用如下类似的代码,就可以得出结论,计算出执行时间。

  一、通用的公式代码

  declare @BeginDdate datetime

  declare @endDdate datetime

  select @BeginDdate = getdate()

  您的SQL语句就写在这里拉

  select @endDdate = getdate()

  select @endDdate - @BeginDdate

  二、示例代码

  declare @BeginDdate datetime

  declare @endDdate datetime

  select @BeginDdate = getdate()

  select * from MyTable where ID>=99

  select @endDdate = getdate()

  select @endDdate - @BeginDdate

  当然,网上的方法比较多,但是,如上的方法是最简单最好理解的了,希望对您有所帮助。


该杂文来自: 数据库Sql,VFP,Access

上一篇:SQL提高查询效益之in、not in、between、like等条

下一篇:SQL两日期时间字段相减求年月日时分秒的代码

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计