Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 March SQL Server: Various options to Drop a user Database

SQL Server: Various options to Drop a user Database

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

” Error – 3702 Drop failed for Database ‘dbrnd’. Cannot drop database “dbrnd” because it is currently in use. SQL Server Drop Database”

I am sure that most of the SQL Server professionals faced above error while dropping a database in SQL Server. There are various ways to drop a database in SQL Server.

You have multiple options to drop a SQL Server Database by closing existing connections.

You cannot execute DROP DATABASE in following situations:

  • The database is currently in use
  • If replicated, the database published
  • A database snapshot exists on the database
  • The database is being mirrored
  • The database is suspect
  • The database is a system database

Following are options to drop a database:

Option #1:
Drop a database using SQL Server Management Studio by selecting an option like “Close existing connections.”

Option #2:
Drop a database using T-SQL Script

Option #3:
Drop a database using Powershell

Option #4:
Set SINGLE User mode and drop a database

1
2
3
4
ALTER DATABASE dbrnd SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE dbrnd
GO
Option #5:
First take a database offline and drop it
Once you take a database offline, it does not drop physical files of database like .mdf and .ldf. You can use Windows Explorer and can drop .mdf and .ldf files.
1
2
3
4
ALTER DATABASE dbrnd SET OFFLINE WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE dbrnd
GO
Option #6:
First SET SINGLE_USER mode and detach the database
Once you detach the database, it does not drop physical files of database like .mdf and .ldf. You can use Windows Explorer and can drop .mdf and .ldf files.
If you do not delete those file, in future again, you can attach your database.
1
EXEC sp_detach_db 'dbrnd', 'true';
Mar 20, 2017Anvesh Patel
SQL Server: SET NOEXEC ON prevent the accidently execution of entire SQL scriptSQL Server: Change the default path of Backup directory and Log files
Comments: 1
  1. Sanon
    June 7, 2018 at 1:56 pm

    great help anvesh, thank you very much

Anvesh Patel
Anvesh Patel

Database Engineer

March 20, 2017 SQL ServerAnvesh Patel, Close Connections, database, database research and development, dbrnd, Drop Database, Drop SQL Database, SQL Query, SQL Server, SQL Server Administrator, SQL Server Error, SQL Server Monitoring, SQL Server Performance Tuning, SQL Server Programming, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....