Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to Check Whether a Global Temporary Exists in a SQL
Database or not?

Answer Posted / guest

Checking whether a table exists in a Microsoft SQL Server
database is easy. You can use this query:

SELECT 'x'
FROM sysobjects
WHERE type = 'U' and NAME = 'mytable'
But this query will not work while searching for global
temporary tables. Global temporary tables are stored in tempdb.
Use this syntax for the search:

DECLARE @temp_table VARCHAR(100)
SET @temp_table = '##my_temp_table'
IF NOT EXISTS (SELECT 'x'
FROM tempdb..sysobjects
WHERE type = 'U' and NAME = @temp_table)
PRINT 'temp table ' + @temp_table + ' does not exist'

ELSE
PRINT 'temp table ' + @temp_table + ' exists.'
Note: You cannot search for local temporary tables (# prefix
tables) in this way. This is because SQL Server appends a
unique number to the name you supply. For example, if you
specified "#temp," the name in sysobjects would be something
like "#temp____1234."

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the new features introduced in SQL Server 2000? What changed between the previous version of SQL Server and the current version?

2362


What is nolock hint in sql server 2008

1127


List the different normalization forms?

980


What is the difference between a "where" clause and a "having" clause?

1160


Explain the purpose of indexes?

976


What is the difference between the export /import functions in sql studio and standalone sql manager? : sql server management studio

1139


Can a stored procedure call itself or recursive stored procedure? How much level sp nesting is possible?

1025


How to use order by with union operators in ms sql server?

1024


What is cursors? And what are the different types of cursor?

1144


How can I create a report based on a query? : sql server management studio

1015


Differentiate between ms sql server reporting services vs crystal reports?

905


How can you stop stored procedures from recompiling?

900


What is a rollup clause?

968


What do you mean by data manipulation language?

1017


What is ms sql server index?

1105