Posted on 2010-01-12
Medium Priority
Last Modified: 2012-05-08
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
EXEC master..sp_MSForeachdb '
USE [?]
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))

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.
Question by:catwalk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 75

Accepted Solution

Aneesh Retnakaran earned 2000 total points
ID: 26298697
>is it possible to use both of these commands together?  
No, you cannot use both of them together

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question