SQL 2005 Course

Samples, Utils and Links from MOC 2780 SQL 2005 Course.

Check All Databases with undocumented stored procedure:

EXEC SP_MSForEachDB @command1=”Print ‘?’ DBCC CHECKDB (‘?’)”

Another track to the same station.

Declare @db VarChar(100),
 @dbid int,
 @hidb int

Select @hidb = Max(dbid ), @dbid = 0 from master..sysdatabases

While @dbid < @hidb
   Set @db = null
   Select @db = name
   From sysdatabases
   Where dbid = @dbid

   if @db is not null
      DBCC CheckDB( @db )

   Set @dbid = @dbid + 1

Reindex all tables in a database:

EXEC sp_MSforeachtable @command1=“print ’?’ DBCC DBREINDEX (’?’, ’ ’, 80)”
EXEC sp_updatestats

By | 2009-02-10T10:01:21+00:00 February 10th, 2009|SQL|0 Comments

About the Author:

Kåre Rude Andersen
Microsoft Certified Trainer since 1996, MCSE, TS and ITP in Microsoft Windows, SQL (also Microsoft), Exchange (MS) and Microsoft Operations Manager. Senior Consultant and have recently worked as a consultant at CSC, SAS, ISS, Nokia and Scandlines.

Leave A Comment