How to create a temp table and a table if it not exits only.

Posted on 2012-04-01
Medium Priority
Last Modified: 2012-04-02
How do i create temporary table tempt.
I have to create it in procedure, and everytime, procedure is called the table should be created and old table should be delted.
Question by:searchsanjaysharma
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Assisted Solution

waltersnowslinarnold earned 500 total points
ID: 37794756
A sample structure is defined below, This should assist you.

CREATE TABLE #tempTableName
LVL 39

Accepted Solution

Pratima Pharande earned 500 total points
ID: 37794758
use this statement before creating tables , replace #tmptable with your tablename

IF OBJECT_ID('tempdb..#tmptable') IS NOT NULL
      DROP TABLE #tmptable
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 500 total points
ID: 37794810
LVL 25

Assisted Solution

jogos earned 500 total points
ID: 37794854
Comments above are good. But your question let me doubt the term 'temp table'.  

In sql server you have temp tables that after your session is finished will be dropped automaticly (so normaly should not exists at next run, except when you do it in query-window without ending the batch), let table start with # (see post before),  with## you get  a global temp table http://www.codeproject.com/Articles/42553/Quick-Overview-Temporary-Tables-in-SQL-Server-2005

You can test before you want to create a table if it does not already exists (see higher).

Author Closing Comment

ID: 37794883

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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