在MSSQL Server中通过查看SQL语句执行所用的时间,来衡量SQL语句的性能。
通过设置STATISTICS我们可以查看执行SQL时的系统情况。选项有PROFILE,IO ,TIME。介绍如下:
SET STATISTICS PROFILE ON:显示分析、编译和执行查询所需的时间(以毫秒为单位)。
SET STATISTICS IO ON:报告与语句内引用的每个表的扫描数、逻辑读取数(在高速缓存中访问的页数)和物理读取数(访问磁盘的次数)有关的信息。
SET STATISTICS TIME ON:显示每个查询执行后的结果集,代表查询执行的配置文件。
语句示例:
SET STATISTICS PROFILE ON; SET STATISTICS IO ON; SET STATISTICS TIME ON; GO /*--你的SQL脚本开始*/ SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[Questions] AS [Extent1] WHERE ( [Extent1].[CheckUser] IS NOT NULL ) AND ( NOT ( ( N'' = [Extent1].[CheckUser] ) AND ( [Extent1].[CheckUser] IS NOT NULL ) ) ) AND ( [Extent1].[Source] IN ( N'xxx1', N'xxx2', N'xxx3' ) ) AND ( [Extent1].[Source] IS NOT NULL ) ) AS [GroupBy1]; /*你的SQL脚本结束*/ GO SET STATISTICS PROFILE OFF; SET STATISTICS IO OFF; SET STATISTICS TIME OFF;
其他参考: