sql server数据库重建索引

查看表索引情况

use DATABASENAME
declare @table_id int

set @table_id=object_id('TABLENAME')

dbcc showcontig(@table_id)

重建数据库所有表的索引

USE DATABASENAME
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)

FETCH NEXT FROM authors_cursor     INTO @name 

END

deallocate authors_cursor

 

posted @ 2021-12-16 16:17  Name=DIC  阅读(332)  评论(0编辑  收藏  举报