Solved

automate sqlcmd to detatch database

Posted on 2008-10-14
2
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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