Dropping temp table . Is there any difference using below sql server 2016 vs sql 2022.

Jose 0 Reputation points
2023-12-30T09:27:03.44+00:00

Temp table is not being dropped when using same query migrating from SQL 2016 to sql 2022 .

Drop table if exists #temp1

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,493 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LiHongMSFT-4306 31,551 Reputation points
    2024-01-02T01:56:32.67+00:00

    Hi @Jose

    How about this code:

    IF OBJECT_ID(N'tempdb..#Temp1') IS NOT NULL
    BEGIN
    DROP TABLE #Temp1 
    END 
    GO
    

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.