Temporary table in SQL server causing ' There is already an object named' error

前端 未结 5 990
难免孤独
难免孤独 2021-02-02 05:10

I have the following issue in SQL Server, I have some code that looks like this:

DROP TABLE #TMPGUARDIAN
CREATE TABLE #TMPGUARDIAN(
LAST_NAME NVARCHAR(30),
FRST_         


        
5条回答
  •  梦毁少年i
    2021-02-02 05:54

    Some times you may make silly mistakes like writing insert query on the same .sql file (in the same workspace/tab) so once you execute the insert query where your create query was written just above and already executed, it will again start executing along with the insert query.

    This is the reason why we are getting the object name (table name) exists already, since it's getting executed for the second time.

    So go to a separate tab to write the insert or drop or whatever queries you are about to execute.

    Or else use comment lines preceding all queries in the same workspace like

    CREATE -- …
    -- Insert query
    INSERT INTO -- …
    

提交回复
热议问题