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 is the difference between a primary key and a unique key? : Sql server database administration

1041


What are rows and columns?

1062


List some of the rules that apply to creating and using a ‘view’

923


What are blobs, tables, and Queues? Is SQL is the standard way to query blobs, tables, and queues?

141


The external application that is executed in one of the tasks does not have a log file, but only a screen log. How can I save the data from the screen? : sql server management studio

1054


Explain the truncate command? : SQL Server Architecture

1230


What is table value parameters (tvp)?

1148


What is log shipping? Can we do logshipping with SQL Server 7.0 ?

1048


How to enable/disable indexes?

1121


How to grant a permission in ms sql server using "grant execute" statements?

1128


How to see existing views in ms sql server?

1105


What is the maximum size of a dimension? : sql server analysis services, ssas

1085


What gets stored inside msdb database?

1308


Relational calculus is what type of language?

1090


What is the difference between left and right outer join?

1112