Thursday, June 28, 2007

Dropping Temp Tables in SQL Server

A typical task in a some stored procedures is to check whether or not a table exists and if so do something with it, perhaps dropping it.

If it is a temp table people sometimes are not sure how to go about this.

Here is some simple code to accomplish the task:


IF OBJECT_ID('tempdb..#tempT') IS NOT NULL
BEGIN
DROP TABLE #tempT
END


Remember that all the temp tables you create actually get created in the tempdb database, which is a system database (not the database you are using!). So replace #tempT with the name of your temp table, but leave the tempdb in there.

6 comments:

Wesley Chapman said...

I was looking for this kind of valuable information.
Your article is really helpful for me. Thanks a lot.


CharityChoice

Kolab

Snupps

Keepcalms

Logopond

Minecraft

Wysp

Codechef

Everplaces

Grabcad

Clarence Beltran said...

I was looking for this kind of valuable information.
Your article is really helpful for me. Thanks a lot.


Issuu

AuthorStream

Rhizome

GetCosmetic

MixCloud

Tvfanatic

Imfaceplate

Linksys

OhmStudio

Backgroundsarchive

kuch bhi said...

Wow, really impressive guide about the topic that I was looking for. Thank you so much for this awesome guide.

Clubcooee

Wesley Chapman said...

Awesome article, I appreciate your efforts.

BROCCAS

Jesus Andrus said...

Awesome article, I appreciate your efforts.

MIDOMI

Jesus Andrus said...

Give your furry friend the gift of comfort with this super soft Calminnng Pet Bed "PowWows" for dogs and cats.
Our beds feature a round design, creating a cozy and protective atmosphere.
Pets will feel surrounded by love and warmth, allowing them to experience truly restful sleep.
The bolstered edge also acts as a headrest, offering additional orthopedic support.