Temp table lives after being explicitly dropped I'm creating a post-deployment script in VS2017 database project.
In this script, I'm using single temp table, which is re-created frequently to adjust to different data structures.

Below you can see a sample excerpt:

    SELECT
        *
    INTO #tmp
    FROM dbo.SourceTable1
    WHERE
        1 = 0

    drop table #tmp


    SELECT
        *
    INTO #tmp
    FROM dbo.SourceTable2
    WHERE
        1 = 0


Unfortunately, when I execute this code, I receive an exception:

Msg 2714, Level 16, State 1, Line 15 There is already an object named '#tmp' in the database.


It looks like the DROP statement is not working here as expected to.
Do you have any idea why does it behave like this?
Try putting a batch separator (GO) command between the SELECT/DROP/SELECT

GO signals the end of a batch of Transact-SQL statements

SELECT *
INTO #tmp
FROM dbo.SourceTable1
WHERE 1 = 0

GO

DROP TABLE #tmp

GO

SELECT *
INTO #tmp
FROM dbo.SourceTable2
WHERE 1 = 0