문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top