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

Does sql server use java?

1006


What are the steps to insert a table?

897


Sql studio em braces a variety of capabilities, but will I need them all? Is there a simpler product ? : sql server management studio

863


What are the types of indexing?

1036


What are system databases in ms sql server?

976


How to make a column nullable?

1048


Explain subquery and state its properties?

976


which table keeps the locking information? : Sql server administration

1020


What is transaction server implicit?

951


Explain iaas, paas and saas?

90


How does using a separate hard drive for several database objects improves performance right away?

889


What is Cross Join and in which scenario do we use Cross Join?

982


What number sorts of privileges are accessible in sql?

985


What are the advantages of passing name-value pairs as parameters?

1116


What are page splits? : SQL Server Architecture

940