Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sys.sp_msforeachdb - dbcc reindex

Status
Not open for further replies.

Bell1991

Programmer
Aug 20, 2003
386
US
I am trying to create a script that will loop through each database and and resbuild indexes on all the tables.
i have
Code:
exec master.sys.sp_MSforeachdb ' USE [?];
DECLARE @starttime datetime, @endtime datetime
print ''?''
EXEC sp_MSforeachtable @command1="DBCC DBREINDEX (''?'')"
SELECT @endtime = GETDATE()
INSERT INTO DBAMain..MaintPlans values (getdate(),''rebuid_indexes'',db_name(), datediff(minute,@StartTime, @EndTime))'

but it is not executing correctly.
I want to record how long each database works and that is why i need to have it this way. I know how to do it if i don't record the time...

any assistance would be great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top