Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Add a database to AG in a stored proc

$
0
0
Each month we have 2 new monthly db's added to an instance. We have some stored procs run that do some work on them and then name them based on the date using variables. We just moved to a 2014 2 node cluster with AG. I have some scripting in place to create the full backups of them after they are built and they are in FULL recovery mode. I was hoping to add steps to the proc to then add these to the AG. I did the wizard and then had it script it out and it comes back with this:[code="sql"]--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.:Connect MyServerPrimaryUSE [master]GOALTER AVAILABILITY GROUP MyAGADD DATABASE [MyDatabase_12012016];GO:Connect MyServerPrimaryBACKUP DATABASE [MyDatabase_12012016] TO DISK = N'\\somelocation\MyDatabase_12012016.bak' WITH COPY_ONLY, FORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5GO:Connect MyServerSecondaryRESTORE DATABASE[/code]Has anyone done something like this in a stored proc? I haven't found much online for this.

Viewing all articles
Browse latest Browse all 3145

Trending Articles