c# - SQL Server Global Temp Table Still Exist After Drop -


i'm trying run query in sql server. inside query there part this:

... if exists(select * tempdb.dbo.sysobjects            id = object_id(n'tempdb.dbo.[##emp]'))      drop table ##emp     select *  ##emp  #emp (nolock) ... 

the thing keep getting error says ##emp exists. how thing possible when checked if exist drop? tried remove if exist part , manually drop table, still says table exists.

check both temp table statuses simple:

select * tempdb..sysobjects name '%emp%' 

then shure handle deletion , recreation both:

begin transaction     ...     if exists(select * tempdb..sysobjects id = object_id(n'tempdb..[#emp]'))         drop table #emp     create table #emp(exampleid uniqueidentifier);     ...     if exists(select * tempdb.dbo.sysobjects id = object_id(n'tempdb.dbo.[##emp]'))          drop table ##emp         select *      ##emp      #emp     ... commit transaction 

as @damien-the-unbeliever pointed out globally visible temporary table can quite troublesome, double check if need it.
in case it's confusing have such similar names...


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -