1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| CREATE PROCEDURE MAINTINDEX
/* Cette procédure permet de reconstruire les index des tables */
AS
SET NOCOUNT ON -- eliminates the sending of number of affected row
-- messages to the client for each statement
DECLARE @TABLE_NAME nvarchar(20)
DECLARE @fillfactor INT
SET @fillfactor = 90
DECLARE DefragIndexcursor
CURSOR FOR
-- Récupération des noms des tables (2 tables) sur les quelles je souhaiterai reconstruire les index
SELECT name
FROM sysobjects
WHERE (xtype = 'U') AND (uid = 5)
OPEN DefragIndexcursor
FETCH NEXT FROM DefragIndexcursor INTO @TABLE_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TABLE_NAME,' ',@fillfactor)
FETCH NEXT
FROM DefragIndexcursor INTO @TABLE_NAME
END
CLOSE DefragIndexcursor
DEALLOCATE DefragIndexcursor
GO |
Partager