--错误的临时表删除操作,因为所在数据库不同 IFEXISTS (SELECT*FROM sysobjects WHEREobject_id=OBJECT_ID(N'[dbo].[#tempTable]') AND type in (N'U')) Begin DROPTABLE[dbo].[tempTable] End --错误的临时表删除操作,因为临时表名已变 ifexists (select*from tempdb.dbo.sysobjects where id =object_id(N'[#temptable]')) Begin droptable #temptable End
2、正确的删除方式:
--正确的临时表删除操作 ifobject_id('tempdb..#tempTable') isnotnullBegin droptable #tempTable End