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.
| Author |
Topic |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2008-07-07 : 14:14:31
|
| I want to execute this stored proc against multiple databases on same server, i have close to 12 identical databases on the same box, each time i need to apply a change then i am executing the same query 12 times pointing to thdatabase.Is it possible to execute the Sp in on shot affecting all of the 12 databases on the same server/box.Please help:**********************example***********USE [Database1]GOALTER PROCEDURE [dbo].[USP_NewTaskCode] (@FieldLabelKey nvarchar(50), @Text nvarchar(10), @Description nvarchar(50), @UserName nvarchar(50)) ASDECLARE @ErrorCode intDECLARE @TransactionCountOnEntry intSET NOCOUNT ONSET TRANSACTION ISOLATION LEVEL SERIALIZABLESELECT @ErrorCode = @@Error, @TransactionCountOnEntry = @@TranCountIF @ErrorCode = 0BEGIN BEGIN TRANSACTION INSERT INTO TAB_TaskCodes (FieldLabelKey, Text, Description, UpdatedBy) VALUES (@FieldLabelKey, @Text, @Description, @UserName) SELECT @ErrorCode = @@Error IF @ErrorCode <> 0 BEGIN ROLLBACK TRANSACTION SET NOCOUNT OFF RETURN @ErrorCode ENDEND -- check if a transaction actually happenedIF @@TranCount > @TransactionCountOnEntry COMMIT TRANSACTIONSET NOCOUNT OFFRETURN @ErrorCode******************************************* |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-07-07 : 14:21:53
|
| sp_MSforEachDB 'exec yourSproc' however your sproc must be in masteror sp_MSforEachDB 'exec ?.dbo.yourSproc'if you have the same sproc in all db's_______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-07 : 14:24:02
|
Or use the SSMSToolsPack built-in tool for this. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-07-07 : 14:32:05
|
even with that you'll need to have the sporc either in master or in every db.but yes, you can use that too _______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out! |
 |
|
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2008-07-07 : 15:21:23
|
Not all the databases on that server, only have 12 db's which need same stored procs.rest all databases belonging to other applications for example: reporting services has its database maintained on the sql server box.Can i use this one: sp_MSforEachDB 'exec yourSproc' Thanks.quote: Originally posted by spirit1 sp_MSforEachDB 'exec yourSproc' however your sproc must be in masteror sp_MSforEachDB 'exec ?.dbo.yourSproc'if you have the same sproc in all db's_______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
|
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-07-07 : 15:26:48
|
| no you can't._______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out! |
 |
|
|
|
|
|
|
|