Guest User

Untitled

a guest
Nov 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. declare @c cursor
  2. , @dbname sysname
  3. , @msg nvarchar(4000)
  4.  
  5. set @c = cursor local fast_forward for
  6. select dbname
  7. from (
  8. select name as dbname
  9. , sys.fn_hadr_is_primary_replica(db.name) as is_primary
  10. from sys.databases db
  11. ) a
  12. where isnull(a.is_primary, 1) = 1
  13. and a.dbname not in (
  14. 'master','model','msdb','tempdb',
  15. 'distribution','DWConfiguration','DWDiagnostics','DWQueue',
  16. 'ReportServer','ReportServerTempDB','SSIS'
  17. )
  18. order by 1
  19.  
  20. open @c
  21. fetch next from @c into @dbname
  22. while @@fetch_status = 0 begin
  23. set @msg = 'Cursors are evil, except when you need them. Which isn''t this time! Anyway, @dbname is: {{dbname}}'
  24. set @msg = replace(@msg, '{{dbname}}', @dbname)
  25. print @msg
  26. fetch next from @c into @dbname
  27. end
  28.  
  29. -- Clean up cursor
  30. close @c
  31. deallocate @c
Add Comment
Please, Sign In to add comment