SQLServer 性能优化工具 数据和工作负荷示例 使用下例说明 SQL Server 性能工具的使用。首先创建下表。 create table testtable (nkey1 int identity, col2 char(300) default 'abc', ckey1 char(1)) 接下来,在这个表中填充 10,000 行测试数据。可以为列 nkey1 中所填充的数据创建非聚集索引。可以为列 ckey1 中的数据创建聚集索引,col2 中的数据仅仅是填充内容,将每一行增加 300 字节。 declare @counter int set @counter = 1 while (@counter <= 2000) begin insert testtable (ckey1) values ('a') insert testtable (ckey1) values ('b') insert testtable (ckey1) values ('c') insert testtable (ckey1) values ('d') insert testtable (ckey1) values ('e') set @counter = @counter + 1 end 数据库服务器将进行下面的两个查询: select ckey1,col2 from testtable where ckey1 = 'a' select nkey1,col2 from testtable where nkey1 = 5000 Profiler SQL Server Profiler 记录数据库服务器中所发生活动的详细信息。可以配置 Profiler 以便用大量的可配置性能信息监视并记录在 SQL Server 中执行查询的一个或多个用户。可在 Profiler 中记录的性能信息有:I/O 统计信息、CPU 统计信息、锁定请求、T-SQL 和 RPC 统计信息、索引和表扫描、警告和引发的错误、数据库对象的创建/除去、连接/断开、存储过程操作、游标操作等等。有关 SQL Profiler 可记录的全部信息,请在 SQL Server Books Online 中搜索字符串“Profiler”。 将 Profiler 信息装载到 .trc 文件中以便用于 Index Tuning Wizard 中 Profiler 和 Index Tuning Wizard 是强大的工具组合,以帮助数据库管理员在表中创建适当的索引。Profiler 将查询所消耗的资源记录在 .trc 文件中。.trc 文件可以由 Index Tuning Wizard 读取,Index Tuning Wizard 同时考虑 .trc 信息和数据库表,然后建议应创建什么样的索引。Index Tuning Wizard 可让管理员选择是自动创建数据库的适当索引,调度索引以便在以后自动创建还是产生一个可以在以后查看和执行的 T-SQL 脚本。 以下是分析查询负荷的步骤: 设置 Profiler 从 SQL Server Enterprise Manager 菜 单中选 择 Tools/SQL Server Profiler 启动 Profiler。 按 CTR...