select *
into #t1
from testcur;
if object_id('tempdb..#t1') is not null
drop table #t1;
select *
into #t1
from testcur;
Is there a way to use create temp table again? In this case #t1
select *
into #t1
from testcur;
if object_id('tempdb..#t1') is not null
drop table #t1;
select *
into #t1
from testcur;
Is there a way to use create temp table again? In this case #t1
If you are going to use this script in SSMS (SQL Server Management Studio), You'll get error which is actually a compile error:
Msg 2714, Level 16, State 1, Line 12
There is already an object named '#t1' in the database.
SSMS does not understand that you have dropped the table and going to create again so it shows you error despite your query is valid.
To make SSMS comfortable with your script use GO before second attempt to create the table
select *
into #t1
from testcur;
if object_id('tempdb..#t1') is not null
drop table #t1;
GO -- use GO
select *
into #t1
from testcur;