Solved

SQL Global Temp Table

Posted on 2013-01-03
4
724 Views
Last Modified: 2013-01-03
if exists (select * from sys.tables where name = N'##Temp02')
drop table ##temp02;    

This T-SQL is not working.  The table ##temp02 is not being dropped?
0
Comment
Question by:dastaub
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
Anuj earned 125 total points
ID: 38742856
You should check in tempdb

if exists (select * from tempdb.sys.tables where name = N'##Temp02')
drop table ##temp02;
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 125 total points
ID: 38742863
This will do..

IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE ID = OBJECT_ID(N'tempdb..##Temp02'))
DROP TABLE ##temp02;
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 250 total points
ID: 38742867
Local temporary tables are destroyed when you close your connection to SQL Server. There is no need to manually purge them under normal circumstances. If you maintain a persistent connection, or connection pooling, you may want to get in the habit of dropping temporary tables immediately after use.

Global temporary tables, on the other hand, since they are visible to all users in a given database, are destroyed along with the last connection which references them
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 250 total points
ID: 38742869
try this

IF OBJECT_ID('tempdb..##Temp02', 'U') IS NOT NULL
   drop TABLE ##Temp02

refer

http://stackoverflow.com/questions/1579363/global-temporary-table-delete-operation
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tempdb latch contention 12 47
sql server query from excel 3 57
Using Aggregate Functions to Count 3 32
Microsoft Azure SQL - create a read only user 2 11
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now