Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop table in Sql Server by Sql Server Management Studio

I deleted a table in SQL Server Management Studio. And then I created a new table with the same name. But the error said that the table has already exists. I want a new completely table with the same name.

like image 613
Jenny Avatar asked Mar 20 '12 17:03

Jenny


2 Answers

Edit: Added more answers after comment.

Are you removing the table from the database diagram or from the object explorer? If you are removing the table from your database diagram using Visual Database tools, it will still exist in the database. From MSDN:

The table is removed from your diagram but it continues to exist in the database.

OR,

Try going to Tools->Options->Designers and unchecking the box that says "Prevent saving changes that require table re-creation". Then try deleting and creating the database.

OR,

Delete the table. Close MS SQL Management Studio. Open MS SQL Management Studio again. Create table.


Old Answer

Are both statements in the same batch? From the Microsoft support page for DROP TABLE:

DROP TABLE and CREATE TABLE should not be executed on the same table in the same batch. Otherwise an unexpected error may occur.

If this isn't the case I'll try to help otherwise. If I can't help otherwise I'll just delete this answer.

like image 113
rownage Avatar answered Nov 09 '22 09:11

rownage


Basically you have one of it open in tab where you get new table...

Steps

  • Close all the tabs
  • When no tabs are open
  • Create you table

And there you are.... It worked for me rather than creating the whole database again.

like image 31
tosha Shah Avatar answered Nov 09 '22 10:11

tosha Shah