Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @c cursor
- , @dbname sysname
- , @msg nvarchar(4000)
- set @c = cursor local fast_forward for
- select dbname
- from (
- select name as dbname
- , sys.fn_hadr_is_primary_replica(db.name) as is_primary
- from sys.databases db
- ) a
- where isnull(a.is_primary, 1) = 1
- and a.dbname not in (
- 'master','model','msdb','tempdb',
- 'distribution','DWConfiguration','DWDiagnostics','DWQueue',
- 'ReportServer','ReportServerTempDB','SSIS'
- )
- order by 1
- open @c
- fetch next from @c into @dbname
- while @@fetch_status = 0 begin
- set @msg = 'Cursors are evil, except when you need them. Which isn''t this time! Anyway, @dbname is: {{dbname}}'
- set @msg = replace(@msg, '{{dbname}}', @dbname)
- print @msg
- fetch next from @c into @dbname
- end
- -- Clean up cursor
- close @c
- deallocate @c
Add Comment
Please, Sign In to add comment