Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Creating a single job for multiple DBs

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-10-06 : 07:33:42
I have a system that has mutliple DB's,and each DB has a job to rebuild indexes and check db consistency. The total number of jobs equates to about 15 jobs.

However, we may have a customer that requires multiple domains for their install of the system. This means that the number of jobs can significantly increase into 100's. Therefore, is there a way to create a single job that can be called against multiple databases?

For instance, can we pass parameters to jobs (such as DB name)?

Hearty head pats

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-10-06 : 07:57:09
Actually, dont worry. I'll just do it all in the SQL

Hearty head pats
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-10-06 : 08:00:13
You'd have to use dynamic sql for this kind of stuff but it should be pretty easy. Taras isp_ALTER_INDEX stored procedure takes the db-name as a parameter and you can just loop through each of the databases in master..sysdatabases table (SELECT name FROM master..sysdatabases) to run it against several databases. I guess you could do something similar for CHECKDB but unfortunately I don't have a script to do it...

-> http://weblogs.sqlteam.com/tarad/archive/2009/03/27/Defragmenting-Indexes-in-SQL-Server-2005Again.aspx

- Lumbago
http://xkcd.com/327/
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-10-06 : 08:02:17
Thanks Lumbago, thats a great help!

Hearty head pats
Go to Top of Page
   

- Advertisement -