Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

How many records can insert into a temp table? Expand / Collapse
Posted Tuesday, March 25, 2014 6:00 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, November 2, 2015 1:32 PM
Points: 345, Visits: 681
I use code below to insert data into a temp table.
How many records can insert into a temp table?

Select * into #temp from ORDER
Post #1554401
Posted Tuesday, March 25, 2014 6:14 AM


Group: General Forum Members
Last Login: Yesterday @ 1:58 PM
Points: 7,164, Visits: 6,537
I don't know of a limit to the number of rows, so I guess it would depend on your available server memory. One thing you should do is watch your use of reserved words as object names. In your query, you should quote your table name like this:

Select * into #temp from [ORDER];

I don't think it'll work without the name quoted because it's a reserved word.

Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1554411
Posted Tuesday, March 25, 2014 12:32 PM



Group: General Forum Members
Last Login: Today @ 2:21 AM
Points: 15,988, Visits: 30,352
Rows will be limited by storage and that's storage in tempdb. Here's a listing of all the limits on SQL Server. Books Online is always one of the single best resources.

"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server Query Performance Tuning
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1554640
Posted Wednesday, March 26, 2014 2:27 AM



Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 43,477, Visits: 40,625
The maximum size of TempDB, like all other databases, is ~525 000 TB, so that's the limit to how many rows you can put into a Temp Table. Probably a bit less, there's other stuff in TempDB as well.

Not limited by available memory because neither TempDB nor temp tables (nor table variables for that matter) are memory-only.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1554818
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse