首页 > 代码库 > sqlserver性能调优常用方法

sqlserver性能调优常用方法

1.检查数据库空间使用情况,查看哪些表占用了比较大的磁盘空间

执行语句如下:

技术分享
select o.name,        SUM(p.reserved_page_count) as reserved_page_count,        SUM(p.used_page_count) as used_page_count,        SUM(        case        when(p.index_id<2) then (p.in_row_data_page_count+        p.lob_used_page_count+p.row_overflow_used_page_count)        else p.lob_used_page_count+p.row_overflow_used_page_count        end        ) as DataPages,        SUM(        case        when (p.index_id<2) then row_count        else 0        end        ) as rowCounts        from sys.dm_db_partition_stats p inner join sys.objects o        on p.object_id=o.object_id        group by o.name        order by rowCounts desc
View Code

 

2.通过活动监视器查看性能消耗

技术分享

通过磁盘IO,CPU占用时间,逻辑读写的次数来判断哪些语句消耗性能比较大

 

3.通过执行时间,磁盘IO和执行计划查看sql语句情况,包括编译执行时间,索引扫描查找,读写等等

查看sql语句的执行时间和表扫描,逻辑读写情况的语句:

SET STATISTICS TIME ON
SET STATISTICS IO ON

技术分享

技术分享

 

sqlserver性能调优常用方法