Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 check existance of table

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-01-26 : 05:59:03
HI,
What is wrong with this query please?
It says: There is already an object named '#tblData' in the database
if EXISTS (
select *
from sys.tables
where name like '#tblData')
DROP TABLE #tblData

Thanks

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-26 : 06:04:51
try:

IF OBJECT_ID('tempdb..#tblData') IS NOT NULL DROP TABLE #tblData


temp tables live in a different database (tempdb) and have to be referenced there. Also, local temp tables have a virutal name ('#tblData' but their real name is like '#tblData_________________________________45AF23') so they can be unique.



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-01-26 : 06:17:50
thank you
Go to Top of Page
   

- Advertisement -