question

cstephen avatar image
cstephen asked

add new database automatically in alwayson availability groups?

Hi team, we recently deployed always on availability groups in our production environment.but every new databases greated in daily.so we added those databases manually in always on availability groups. so we need a automation to identify new databases in sql server and added a automatically in availability groups. Is there any scripts there for adding new databases automatically in existing availability groups in environment?share with me Regards stephen
sql serveralways-onalwayson
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
If you do a web search there are a number of different articles on how to do this. It's pretty straight forward. The documentation [over at MSDN][1] has examples of how to use T-SQL to add a database to an Availability Group. You can then use a [DDL trigger][2] to have the script fire each time you create a database, assuming you just don't add this script to whatever scripts are running to create databases. [1]: https://technet.microsoft.com/en-us/library/hh213078(v=sql.110).aspx [2]: https://msdn.microsoft.com/en-us/library/ms175941.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.