Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

automate sqlcmd to detatch database

Posted on 2008-10-14
2
Medium Priority
?
354 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

618 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