重建資料庫表所有索引

2021-04-08 16:13:36 字數 992 閱讀 6810

/***********************

重建資料庫表所有索引

2006-06-12

先選擇要修復的資料庫

***********************/

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, '', 70)

-- get the next author.

fetch next from authors_cursor

into @name

end/***********************

重建指定表的索引

2006-06-12

先選擇要修復的資料庫

***********************/

--第一步:檢視是否需要維護,檢視掃瞄密度/scan density是否為100%

declare @table_id int

set @table_id=object_id('表名')

dbcc showcontig(@table_id)

--第二步:重構表索引

dbcc dbreindex('表名',pk_索引名,100)

--重做第一步,如發現掃瞄密度/scan density還是小於100%則重構表的所有索引

--並不一定能達100%。

dbcc dbreindex('表名','',100) 

重建資料庫表所有索引

重建資料庫表所有索引 2006 06 12 先選擇要修復的資料庫 declare name nvarchar 255 所有使用者表游標 declare authors cursor cursor for select name from sysobjects where xtype u order ...

重建ORACLE資料庫索引

declare str varchar2 400 begin 重建oracle索引 for tmp idx in select tablespace name,owner,table name,index name from all indexes where owner hnacms and te...

SQL 建立索引,遍歷資料庫所有表

檢視資料庫表占用的磁碟空間 執行儲存過程 exec sp spaceused tablename 建立聚簇索引 create clustered index indexname on tablename columnname 不允許有重覆記錄 create index clustered index...