March 13, 2008 at 7:57 am
You also have the option of adding a single sql agent job and separate job steps for each database.
you can also try this in a single job step:
use xxxxxx
go
exec myproc
go
use xxxxx
go
exec myproc
....
March 13, 2008 at 8:46 am
sp_msforeachdb "exec mydb..myProc"
March 13, 2008 at 9:20 am
If there is common data used by multiple databases of a single application, it is unfortunate that the application designers didn't think to use an Application Master database for housing and accessing that data.
March 13, 2008 at 9:41 am
you can use something like
declare @dbname varchar(300)
declare @sqlstring varchar(500)
select @dbname = max(name) from master.dbo.sysdatabases
while @dbname is not null
begin
set @sqlstring = 'use '+ @dbname + ' update tableA set column1 = '
exec (@sqlstring)
select @dbname = max(name) from master.dbo.sysdatabases
where name < @dbname
end
March 13, 2008 at 11:18 am
ForEachDB would simply this process for you 10 fold. As mentioned earlier, it does uses cursors, but is so dang convientent.
Your statement should look like this:
EXEC master..sp_MSForeachdb '
USE [?]
IF DB_ID(''?'') > 4 --dont do system dbs
IF ''?'' <> ''DB41''
AND ''?'' <> ''DB42''
AND ''?'' <> ''DB43''
AND ''?'' <> ''DB44''
AND ''?'' <> ''DB45''
BEGIN
EXEC stored procedure
END
'
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply