• 众所周知随着表的数据量不断增长,会产生很多索引的碎片。这时候需要重建索引来提高查询性能。
    USE [DBName]
    
    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  --将游标向下移1行,获取的数据放入之前定义的变量@name
     
    WHILE @@FETCH_STATUS = 0  -- 正常读取
    BEGIN    
       DBCC DBREINDEX (@name, '', 90)
       FETCH NEXT FROM authors_cursor  
       INTO @name 
    END
     
    deallocate authors_cursor  --释放游标

     

  • 你也可以把脚本执行计划设置到定时执行任务计划之内

相关文章:

  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案