重新生成SqlServer所有索引

脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
USE YOUR_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

WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX (@name, '', 90)
print @name
FETCH NEXT FROM authors_cursor
INTO @name
END

deallocate authors_cursor