Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)归海一刀published in(发表于) 2014/2/3 6:42:56 加快Sql server时间查询速度的办法_[SQL Server教程]
数据量大的情况下Sql server时间比较查询的速度是比较慢的,如果在access中进行时间的比较,sql语句很简单,select * from table where thetime>#\"& now() &\"#这样即可。但在mssql就不能这样,要用datediff语句和getdate()函数进行比较。 如select count(*) from table where datediff(s,getdate(),thetime)>0,我自己特别做了个50万条数据的的表,执行这条语句差不多需要1200毫秒。 后来研究了一下,发现其实不需要用datediff函数,可以直接使用>来比较,语句如下:select count(*) from table where thetime>getdate(),这样差不多只要750毫秒,快了将近500毫秒,实验结果此方法值得使用。
赞