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.
3 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.
-
I didn't write any statement. I deleted and created tables using ms sql server management studio. I mean "I deleted a table. It disappeared in server explorer. But it still exists. I want to completely remove it. plz help me again."– JennyMar 20, 2012 at 19:04
-
Edited my answer. If you go into Object Explorer, right click the table, and press Delete, it should delete it completely unless you don't have permissions or you need to do one of the things in my edited answer. Can you check it out and let me know how you make out?– rownageMar 20, 2012 at 19:39
-
Ohh,Thanks. I could make it out. The source of the problem is I have to uncheck "Preventing saving changes that require table re-creation".– JennyMar 20, 2012 at 23:31
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.
Clock on Tools -> Options -> Designers -> UNcheck Prevent table changes from table re-creation check box.