select *
from tempdb.sys.objects
where 1=1
and CHARINDEX('#tmp',name)>0
select *
from tempdb.sys.columns
where 1=1
and object_id IN (
select *
from tempdb.sys.objects
where 1=1
and CHARINDEX('#tmp',name)>0)
if OBJECT_ID(N'tempdb.dbo.#temp')is not null
select '存在'
if OBJECT_ID(N'tempdb..#temp')is not null
select '存在'