Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Insert Into @DBs (DBName)
- Select D.name
- From sys.databases As D
- Where D.database_id > 4
- And D.state = 0
- And is_read_only = 0
- And D.source_database_id Is Null
- And Not Exists (SELECT 1 FROM sys.dm_hadr_database_replica_states AS hdrs
- INNER JOIN sys.availability_replicas AS ar ON hdrs.replica_id = ar.replica_id
- INNER JOIN sys.dm_hadr_availability_replica_states AS hars ON hdrs.replica_id = hars.replica_id
- Where hars.role_desc = 'SECONDARY'
- And ar.replica_server_name = @@SERVERNAME
- And hdrs.database_id = D.database_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement