zoukankan      html  css  js  c++  java
  • SQL Server 调优系列进阶篇

    随着数据的数据量的急剧增加,数据库的性能也会明显的有些缓慢这个时候你可以考虑下重建索引或是重新组织索引了。

    DBCC SHOWCONTIG('表名') 可以查看当前表的索引碎情况。

    重建索引

    方法一:

    DECLARE @name varchar(100)  
      
    DECLARE authors_cursor CURSOR FOR Select [name] from sysobjects where xtype='u' order by id  
      
    OPEN authors_cursor  
      
    FETCH NEXT FROM authors_cursor INTO @name  
      
    WHILE @@FETCH_STATUS = 0   
    BEGIN      
      
        DBCC DBREINDEX (@name, '', 90)  
        /*--填充因子:90,建议60-90之间,100的查询性能最好,但插入数据后会导致索引页迁移会影响修改的性能.*/
        FETCH NEXT FROM authors_cursor    
        INTO @name   
    END  
    
    Close authors_cursor
    Deallocate authors_cursor 

    方法二:

    DECLARE  tables CURSOR for select name from sysobjects where xtype='U'
    
    DECLARE @table_name char(128)
    
    Open tables
    
    Fetch next from tables into @table_name
    
    While @@fetch_status=0
    Begin
        EXECUTE ('ALTER INDEX ALL ON ' + @table_name + ' REBUILD')
        Fetch next from tables into @table_name
    End
    
    Close tables
    Deallocate tables
  • 相关阅读:
    文件操作
    苹果越狱
    猫的期幻之旅-20130114
    js传url中文参数乱码问题
    JS三元
    SQL同列合并
    数据库引擎介绍innodb和myisam
    数据库优化
    gleez 下分页功能优化
    kohana安装总结
  • 原文地址:https://www.cnblogs.com/MuNet/p/5886216.html
Copyright © 2011-2022 走看看