Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

DB Reindex all Databases Expand / Collapse
Posted Sunday, September 23, 2007 2:07 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, January 29, 2009 6:50 PM
Points: 31, Visits: 2
Comments posted to this topic are about the item DB Reindex all Databases

Post #401710
Posted Tuesday, May 5, 2009 4:40 PM



Group: General Forum Members
Last Login: Friday, October 14, 2016 12:07 PM
Points: 1,518, Visits: 3,694
I would suggest two changes where you declare the cursor:

declare db cursor for
select name from master.dbo.sysdatabases
where name not in ('master','tempdb')
and charindex('-',name) = 0
and version <> 0

Checking the version prevents trying to reindex an offline database, the charindex prevents processing of databases that contain a dash in their name: the code would otherwise fail. This is for SQL Server 2000, I'm not sure if it would be implemented the same way in later versions.

Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson
Post #710726
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse