Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

sql

I am attempting to write a query that will loop through all the databases and rebuild all the indexes for each table.

I would like to use sp_msforeachtable and msp_msforeachdb
[code]
EXEC master..sp_MSForeachdb '
USE [?]
BEGIN
declare @starttime datetime
set @starttime = getdate()
print ''?''
EXEC sp_MSforeachtable @command1="DBCC DBREINDEX (''?'')"
declare @endtime datetime
SELECT @endtime = GETDATE()
INSERT INTO DBADB..MaintPlans values (getdate(), ''indexes'',db_name(), datediff(minute,@StartTime, @EndTime))
END'
GO
[/code]

and i am receiving an error.  is it possible to use both of these commands together?  Also, i would like to include the fillfactor = 90% (DBCC REINDEX ( tablename, '', 90)

Any assistance you could provide would be great.
0
catwalk
Asked:
catwalk
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
>is it possible to use both of these commands together?  
No, you cannot use both of them together
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now