Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:17:06+00:00 2026-06-12T09:17:06+00:00

I’m working with SQL Server 2008 and I can’t seem to do drop and

  • 0

I’m working with SQL Server 2008 and I can’t seem to do drop and create a database.

I’ve tried a few different ways but I always end up failing to drop or trying to “use” before it seems to be created.

My current attempt looks like this.

use master;
GO
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'test')
BEGIN
DROP DATABASE [test];
END
GO
CREATE DATABASE [test];
GO
use [test];
GO

The GO were suggested on a MS forum as a way to stop some issues that occur when selecting databases.

With this I currently get the output (with a ore existing database of the same name) of:

Msg 3702, Level 16, State 4, Line 3
Cannot drop database “test” because it is currently in use.
Msg 1801, Level 16, State 3, Line 1
Database ‘test’ already exists. Choose a different database name.
Msg 2714, Level 16, State 6, Line 2
There is already an object named ‘staff_type’ in the database.

With the last 2 lines repeated for every table in my database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:17:07+00:00Added an answer on June 12, 2026 at 9:17 am

    We usually get this error If You’ve opened any query window with connection to this database, so make sure you close all your opened query windows connected to db which you’re trying to drop.

    Don’t use the database which you’re trying to drop. use master to drop any user database that is a good practice.

    Make sure No other process is attach to the database you’re trying to drop.

    EXEC sp_who2
    --Run kill spid for each process that is using the database to be dropped.
    kill <<processid>> -- Kill 57
    

    Use EXEC sp_who2 and check the DBName column, your database name should not appear in the list, if it appears kill the process using kill <<processid>> then try to drop.

    Try this code.

    use master
    GO
    
    IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'test')
    DROP DATABASE [test]
    GO
    
    CREATE DATABASE [test]
    GO
    
    use [test]
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tracked down a weird MySQL problem to the two different ways I was
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.