Solved

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

Posted on 2012-04-01
5
280 Views
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.
0
Comment
Question by:searchsanjaysharma
5 Comments
 
LVL 7

Assisted Solution

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

CREATE TABLE #tempTableName
(
col1 DATATYPE,
col2 DATATYPE,
..
..
)
0
 
LVL 39

Accepted Solution

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


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

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 125 total points
ID: 37794810
0
 
LVL 25

Assisted Solution

by:jogos
jogos earned 125 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).
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37794883
ok
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PERFORMANCE OF SQL QUERY 13 76
sql Audit table 3 74
execute a MS SQL script as a schedule SQL job 72 138
passing parameter in sql procedure 9 65
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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