473,473 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Temp tables vs table variables

I am running SQL Server Best Practices on a SQL 2000
database and it is recommending me to change the temp
tables inside SPs to table variables.

I had read already in other places to use table variables
over temp tables. I also know I can't create indexes as
I can on temp tables. Instead I'll have to create either
a primary key and/or a unique index on a table variable.

One question I have is let's say I will be putting thousands
of records in a temp table, should i still choose a table
variable over a temp table for this? Or is there a
recommended limit where if I have to store certain
number of records then it's better to store them in
a temp table rather than a table variable? Or number
of records is not the factor to decide whether to use
temp tables or table variables?

I would like to know when it's ideal or best to use
temp tables instead of table variables and vice versa.

Thank you
Dec 14 '05 #1
1 4448
On Wed, 14 Dec 2005 13:04:05 -0500, serge wrote:
I am running SQL Server Best Practices on a SQL 2000
database and it is recommending me to change the temp
tables inside SPs to table variables.

I had read already in other places to use table variables
over temp tables. I also know I can't create indexes as
I can on temp tables. Instead I'll have to create either
a primary key and/or a unique index on a table variable.

One question I have is let's say I will be putting thousands
of records in a temp table, should i still choose a table
variable over a temp table for this? Or is there a
recommended limit where if I have to store certain
number of records then it's better to store them in
a temp table rather than a table variable? Or number
of records is not the factor to decide whether to use
temp tables or table variables?

I would like to know when it's ideal or best to use
temp tables instead of table variables and vice versa.

Thank you


Hi Serge,

There is no hard and fast rule. Testing is the only way to find out for
sure which solution will be best in your situation.

As a rule of thumb, therre tends to be some bias towards table variables
for small amounts of data and towards temp tables for large amounts of
data.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Dec 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rick Hein | last post by:
I have an application that I am working on that uses some small temp tables. I am considering moving them to Table Variables - Would this be a performance enhancement? Some background...
3
by: Rebecca Lovelace | last post by:
For some reason in Enterprise Manager for SQL Server 2000, I cannot put the following line into a trigger: select * into #deleted from deleted When I hit the Apply button I get the following...
3
by: Subodh | last post by:
I've written a SP which does some complex calculations and in the end dumps data into 2 tables (master & detail) When I run this sp for smaller no of IDS (employees i.e for 13000 in Master and...
21
by: Boris Popov | last post by:
Hello pgsql-general, I'm trying to implement a table with rows that are automatically deleted when the session that inserted them disconnects, sort of like our own alternative to...
1
by: Robert McEuen | last post by:
Using Access 97 on WinXP I have data in a DB2 table that I'm trying to get into an identical table in my backend db. Based on volume of data and frequency of download, I'm trying to avoid...
16
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
2
by: Burbletrack | last post by:
Hi All, Hope someone can help me... Im trying to highlight the advantages of using table variables as apposed to temp tables within single scope. My manager seems to believe that table...
0
by: cuddles | last post by:
hi all i need to declare a temporary table within a user-defined function in IBM DB2 ver 8. can someone give me the syntax for the temp table declaration. CREATE FUNCTION PEGASUS.readOrder(...
4
by: R. K. Wijayaratne | last post by:
Hi everyone, I have a SPROC which selects records into a MSSQL #temp table and then selects the records from that. I drag this SPROC onto the right-hand pane of the DBML diagram, but the method...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.