• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

automate sqlcmd to detatch database

I am looking to Automate a SQL script file for detaching a database using sqlcmd console. can anyone help me out with this?

thanks
0
IGCNTech
Asked:
IGCNTech
1 Solution
 
BrandonGalderisiCommented:
sqlcmd -Syourservername -E -dmaster -Q"sp_detach_db 'YOURDATABASENAME'"

-E is trusted connection, either use that or -U and -P for password
-dmaster : you want to ensure that you don't accidentally end up in the DB to be detached due to default database settings.

There are other things to consider:
What if users are in the DB currently?
What if users have that DB set as their default DB?  Removing the Db could prevent them from logging in.
0
 
IGCNTechAuthor Commented:
this was exactly what I was looking for.
thanks for your help.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now