Drop table, then cannot recreate table with the same name
I first drop a table in SQL Server 2008 (after that it shows the message that the command was executed sucessfully).
I then tried to create a table with the same name, and it showed me an error.
After closing the SSMS window and re opening it it tried to create the table with the same name again and it succeeded.
What is going on?
You can't drop and create the same table in the same batch in sql server see MSDN
Their examples use GO to break up the two commands. Semi colon might work,
Drop Table ...; Create Table ,,,;
as might
Begin Transaction
Drop Table...
Commit Transaction
Create Table
Or of course splitting it up into two commands, which is what GO does in SQL server manager's query window.
If you do split it up, it might be wise to check whether the table exists before trying to drop it, and that it doesn't before trying to create it.
链接地址: http://www.djcxy.com/p/94426.html上一篇: 将标识添加到现有列
下一篇: 删除表,然后不能重新创建具有相同名称的表