Solved

automate sqlcmd to detatch database

Posted on 2008-10-14
2
339 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

937 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

5 Experts available now in Live!

Get 1:1 Help Now