create Table #Report
(
ID int IDENTITY PRIMARY KEY,
bookId int,
bookName varchar(50)
)
go
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Report'))
select '#Report表存在!'
else
select '#Report表不存在!
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Report'))
begin
select '#Report表存在!'
drop Table #Report
end
else
select '#Report表不存在!'
-----------------------
if exists (select top 1 * from #Report)
begin
....
end
-----------------------------------------------
方法1:
if object_id('tempdb..yourtemptablename') is not null
drop table tempdb..yourtemptablename
方法2:
if exists(select 1 from tempdb..sysobjects where type = 'U' and name like 'yourtemptablename%')
drop table tempdb..yourtemptablename
比較
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InfoCategory]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[InfoCategory]