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

前端 未结 5 986
难免孤独
难免孤独 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条回答
  •  北海茫月
    2021-02-02 06:09

    You are dropping it, then creating it, then trying to create it again by using SELECT INTO. Change to:

    DROP TABLE #TMPGUARDIAN
    CREATE TABLE #TMPGUARDIAN(
    LAST_NAME NVARCHAR(30),
    FRST_NAME NVARCHAR(30))  
    
    INSERT INTO #TMPGUARDIAN 
    SELECT LAST_NAME,FRST_NAME  
    FROM TBL_PEOPLE
    

    In MS SQL Server you can create a table without a CREATE TABLE statement by using SELECT INTO

提交回复
热议问题