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
 Other Forums
 Other Topics
 how to check if a temp table exists

Author  Topic 

sqlguru
SQLTeam CoFounder

20 Posts

Posted - 2000-08-09 : 00:00:00
Alex L writes "I know that we can use information_schema.tables and If exists (....) to check for the existence of a table. How can I do the same thing for a temporary table, which exists in tempdb? I work with SQLserver 7.0 and Windows NT 4.0.
"


Alex,

My favorite method is to use something like the following:

IF object_id("tempdb..foo") is not null
BEGIN
  --stuff to do if table exists
  --object_id returns a non-null value if the object exists
END

hope this helps,
Sean

   

- Advertisement -