How to Check Whether a Global Temporary Exists in a SQL
Database or not?
Answers were Sorted based on User's Feedback
Answer / 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 |
What is indexing explain it with an example?
how we can count records as a group of days like sum of records for(four mondays),(four tuesday)........ in a month. group the column for weekdays.
Assume,there are three tables in a database, Can i have both primary key and foreign key for each table in the same database?
How to delete duplicate rows in sql server?
How to add a new column to an existing table with "alter table ... Add" in ms sql server?
Why use “in” clause in sql server?
How many types of relations are there between dimension and measure group? : sql server analysis services, ssas
how to change column into row in sql
Does the unique constraint create an index?
What is the name of the Database which IBM mainframe uses?
What are the magic tables in SQL Server 2000?
7 Answers Infogain, Merrill Lynch,
Can I remove the default constraint columns in SQL SERVER?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)