question

KishoreKaruppanasamy-7446 avatar image
0 Votes"
KishoreKaruppanasamy-7446 asked ErlandSommarskog commented

Dropping database on another SQL Server instance

In the process of automating DB restores on AlwaysOn enabled environment, we are in need to drop the DBs (which are sometimes struck in restoring state) in the secondary servers. I am using the linked server configured between the nodes to drop the DBs on secondary server before adding the restored Dbs back in to AlwaysOn AG.

Is there an other way I can drop DBs on another SQL server instance without using linked server?

sql-server-generalsql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered ErlandSommarskog commented

Yes, by running a Powershell script or similar from outside SQL Server. For admin things that span servers, Powershell is often a better option.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your reply. Found the script:

invoke-sqlcmd -ServerInstance "servername" -U "sa" -P "Plain text password" -Query "Drop database DBname;"

0 Votes 0 ·
AmeliaGu-msft avatar image AmeliaGu-msft KishoreKaruppanasamy-7446 ·

Hi KishoreKaruppanasamy-7446,
Did the answer help you?
Please feel free to let us know if you have any other question.
If you find any post in the thread is helpful, you could kindly accept it as answer.

Best Regards,
Amelia

0 Votes 0 ·
ErlandSommarskog avatar image ErlandSommarskog KishoreKaruppanasamy-7446 ·

Great you found the script on your own. I was kind of fearing that you would ask for how to do it, but I don't use PowerShell that much myself. Just because I know what is best practice, does not mean that I always adhere to it. :-)

0 Votes 0 ·