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 '# The report table exists! '
Else
Select '# The report table does not exist!
If exists (select * From tempdb .. sysobjects where id = object_id ('tempdb .. # Report '))
Begin
Select '# The report table exists! '
Drop table # report
End
Else
Select '# The report table does not exist! '
-----------------------
If exists (select top 1 * from # Report)
Begin
....
End
-----------------------------------------------
Method 1:
If object_id ('tempdb .. yourtemptablename') is not null
Drop table tempdb .. yourtemptablename
Method 2:
If exists (select 1 from tempdb .. sysobjects where type = 'U' and name like 'yourtemptablename % ')
Drop table tempdb .. yourtemptablename
Comparison
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [infocategory] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [infocategory]