How to run script on multiple databases

I have a SQL maintenance script that I want to run on multiple databases instead of having to run it manually against each database.  Is there a way of creating a job or something to allow this to happen?

Thank you in advance for your help.
LVL 1
cjrcomputersAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marten RuneSQL Expert/Infrastructure ArchitectCommented:
If you create a job, you can have one jobstep for dbOne, and let jobstep two take care of dbTwo, etc etc

//Marten
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cjrcomputersAuthor Commented:
I was hoping I wouldn't have to create a step for each database as there's 11 of them, but if thats the only way I guess I'll have to.
0
ralmadaCommented:
Have you considered using the sp_msforeachdb procedure?
Check these links for details:
http://blogs.techrepublic.com.com/datacenter/?p=395 
http://www.mssqltips.com/tip.asp?tip=1414 
0
cjrcomputersAuthor Commented:
Well I would use that procedure, but I don't want to do it on all of the databases on the server.  I think I'll just have to created a job with a step for each database.
0
ralmadaCommented:
I guess you didn't read the links, you can selectively run the script based on the database name. check this part of the first link:
EXECUTE sp_msforeachdb 'USE ?
IF DB_NAME() NOT IN(''master'',''msdb'',''tempdb'',''model'')
BACKUP DATABASE ? TO DISK = ''G:?.bak, WITH INIT'''

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.