Solved

automate sqlcmd to detatch database

Posted on 2008-10-14
2
337 Views
Last Modified: 2012-08-14
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
Comment
Question by:IGCNTech
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22711959
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
 

Author Closing Comment

by:IGCNTech
ID: 31505890
this was exactly what I was looking for.
thanks for your help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now