create proc temp(@tablename varchar(200))
as
declare @exec varchar(8000)
set @exec='use tempdb
if exists(select * from sysobjects
where id=object_id(''tempdb..'+@tablename+'''))
print '''+@tablename+'表存在''
else
print '''+@tablename+'表不存在'''
exec (@exec)--测试
create table #test(id int,name varchar(20))temp '#test'
go
temp '#test1'
-----------
#test表存在
#test1表不存在
as
declare @exec varchar(8000)
set @exec='use tempdb
if exists(select * from sysobjects
where id=object_id(''tempdb..'+@tablename+'''))
print '''+@tablename+'表存在''
else
print '''+@tablename+'表不存在'''
exec (@exec)--测试
create table #test(id int,name varchar(20))temp '#test'
go
temp '#test1'
-----------
#test表存在
#test1表不存在
as
declare @exec varchar(8000)
set @exec='use tempdb
if exists(select * from sysobjects
where id=object_id(''tempdb..'+@tablename+'''))
print '''+@tablename+'表存在''
else
print '''+@tablename+'表不存在'''
exec (@exec)go--测试
create table #test(id int,name varchar(20))
go
temp '#test'
go
temp '#test1'
-----------
#test表存在
#test1表不存在
-------------------------------------
------------------------------------
以上语句表示如果#TableName 临时表存在则直接做删除处理
drop table #pzgrid Create table #pzgrid