When writing scripts you often need to change the columns in a temp table. Despite being guarded by drop-table-if-exists statements it fails because the columns have not changed. Why?
An example that shows roughly what I mean, why doesn't this script work? It fails when recreating #t saying "There is already an object named '#t' in the database.".
It feels like SQL server cheats and only empties the table and not dropping it.
if exists (select * from tempdb..sysobjects where id=object_id('tempdb..#t'))
    drop table #t
create table #t (
    a int
)
if exists (select * from tempdb..sysobjects where id=object_id('tempdb..#t'))
    drop table #t
create table #t (
    a int
    ,b int
)
 
     
     
     
     
    