Example and Notes
Re-indexing can help restore performance in the right circumstances, but production maintenance should consider database size, uptime needs, fill factor, and statistics.
Create Procedure uspReindex
AS
DECLARE @TableName varchar(255)
DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName,' ',90)
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
Production Review
WSI can adapt this script for your database, improve error handling, tune performance, document the logic, and help deploy it safely.