September 2, 2019 at 10:26 am
I have written some dynamic SQL that executes a stored procedure in all databases it exists in.
I now need to Create A Stored Proc Across All DBs Where That DB Exists in An Availability Group.
Ideally I would like to execute the stored proc if it already exists, and create the stored proc if it doesn't exist.
Thanks in advance for any help.
Kind regards,
George
September 2, 2019 at 11:25 am
I can't give you a full answer but for identifying if the database is part of a group maybe you can query sys.dm_hadr_database_replica_cluster_states (https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-hadr-availability-group-states-transact-sql?view=sql-server-2017) using the database_name field in a where clause? I think you should get an empty result if the server isn't part of an availability group.
September 3, 2019 at 9:52 am
Hi as1981.
Thank you for your response. I have tried that and that is good for that part of the query.
I shall try and work on the rest of it.
Thanks again.
George
September 4, 2019 at 9:06 am
CREATE OR ALTER should be your syntax in 2016+
September 4, 2019 at 9:20 am
This was removed by the editor as SPAM
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply