I am trying to create a script that will loop through each database and and resbuild indexes on all the tables.
i have
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.
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.