SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Temp Tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vijayshankar2003
Starting Member

India
4 Posts

Posted - 08/18/2012 :  17:18:20  Show Profile  Reply with Quote
Hello friends, i just want to know why do we use temp table to insert values first and then later move those values to the main table. While inserting, we do delete or discard the temp tables.

Happiness is the best habit to cultivate. Do not serach for it, its there beside you.

visakh16
Very Important crosS Applying yaK Herder

India
47157 Posts

Posted - 08/18/2012 :  17:28:49  Show Profile  Reply with Quote
its not a necessity but it really depends on your scenario. In some cases you would require some intermediate processing before you get data in required format as per your destination table thats when you make use Temp tables. The choice of temp tables against table variable for doing the processing depends on lots of other factors like size of dataset, scope to which you want to persist the resultset etc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1770 Posts

Posted - 08/19/2012 :  01:40:01  Show Profile  Visit jackv's Homepage  Reply with Quote
Generally, if no indexes are required and the dataset if ~ < 75000 rows I'll consider Table variables. Otherwise I'll use temp tables if temporary storage and manipulation is required.

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

vijayshankar2003
Starting Member

India
4 Posts

Posted - 08/19/2012 :  05:02:45  Show Profile  Reply with Quote

Thanks for ur reply guys.. since am new to the world of sequel programming, can u brief on that intermediate proceesing you mentioned. For example, i just want to out the values on the click of a button. But my guidelines suggest me to first save the values in a temp table and later move the values into main table and out the values from it. Why not instead directly out the value from main table. Is their any protocol or coding guidelines followed for this? Hope am clear to you.



Happiness is the best habit to cultivate. Do not serach for it, its there beside you.

Edited by - vijayshankar2003 on 08/19/2012 05:36:13
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1770 Posts

Posted - 08/19/2012 :  06:37:16  Show Profile  Visit jackv's Homepage  Reply with Quote
Which guidelines do you mean? From a SQL Serve perspective, temporary tables were designed for storage and manipulation of temporal data. They are instantiated in TempDB - and are not permanent tables. SQL Server Books Online , has some excellent usage guidelines

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47157 Posts

Posted - 08/19/2012 :  10:19:52  Show Profile  Reply with Quote
quote:
Originally posted by vijayshankar2003


Thanks for ur reply guys.. since am new to the world of sequel programming, can u brief on that intermediate proceesing you mentioned. For example, i just want to out the values on the click of a button. But my guidelines suggest me to first save the values in a temp table and later move the values into main table and out the values from it. Why not instead directly out the value from main table. Is their any protocol or coding guidelines followed for this? Hope am clear to you.



Happiness is the best habit to cultivate. Do not serach for it, its there beside you.


if its just retrieving the data from table without any intermediate processing then you can use main table itself

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1770 Posts

Posted - 08/20/2012 :  01:35:59  Show Profile  Visit jackv's Homepage  Reply with Quote
Are you able to show the SQL Code you're running?

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

vijayshankar2003
Starting Member

India
4 Posts

Posted - 08/26/2012 :  13:58:36  Show Profile  Reply with Quote
I shall try to explain my scenario clearly.. On the click of a button, the selected values should get saved in a table and later when i try to maintain that same value, it should get updated and the new one should get saved .... So what i do now is, i first insert those values in a temp table and then i move it to main table. While moving it to main table, i delete the temp table with the respective guid created for the record..
hope am clear to you...!

Vijay Shankar
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47157 Posts

Posted - 08/26/2012 :  14:31:39  Show Profile  Reply with Quote
quote:
Originally posted by vijayshankar2003

I shall try to explain my scenario clearly.. On the click of a button, the selected values should get saved in a table and later when i try to maintain that same value, it should get updated and the new one should get saved .... So what i do now is, i first insert those values in a temp table and then i move it to main table. While moving it to main table, i delete the temp table with the respective guid created for the record..
hope am clear to you...!

Vijay Shankar


If there are no intermediate processing and its straight saving of values on click of button, there's no need for usage of temporary tables. You can directly do inserts on main table itself. But if there's some intermediate processing like Aggregation, some row level processing etc then temp table is required to hold intermediate results

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000