Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare @MaxID int,
- @CurrID int,
- @SQL nvarchar(100)
- Declare @DBs Table (DBID int identity(1, 1) not null primary key,
- DBName sysname not null unique)
- Set NoCount On;
- Insert Into @DBs (DBName)
- Select name
- from sys.databases
- -- 0 = online
- Where state = 0
- -- Not a snapshot
- And source_database_id Is Null
- -- Not marked read-only
- And is_read_only = 0;
- Select @MaxID = MAX(DBID),
- @CurrID = 1
- From @DBs
- While @CurrID <= @MaxID
- Begin
- Select @SQL = 'Use ' + QUOTENAME(DBName) + ';
- If OBJECT_ID(''dbo.MyProcedure'') Is Not Null
- Exec dbo.MyProcedure;'
- From @DBs
- Where DBID = @CurrID
- Exec sp_executesql @SQL;
- Set @CurrID = @CurrID + 1
- End
- Set NoCount Off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement