Skip to main content
57 votes
Accepted

Is it generally faster to select into a temp table than selecting into an actual table?

writing to tempdb is faster than an actual table not in tempdb It's true. There are two IO enhancements in TempDb. Writes to a table in a user database must have their log records flushed to disk ...
David Browne - Microsoft's user avatar
29 votes
Accepted

What happens when there is no available physical memory left for SQL Server?

when there is no physical memory left for data, then SQL Server moves the already existing data into TEMPDB The article you linked to is misleading at best, and incorrect in some places. I think the ...
Josh Darnell's user avatar
  • 29.8k
18 votes
Accepted

How to inspect global temp table from outside the transaction it is created in

File this under "just because you can, doesn't mean you should" If you generate a bind token in the first session, and somehow publish it, you can join its transaction from another session. Eg from ...
David Browne - Microsoft's user avatar
16 votes

What is hot spotting in the context of adding files to tempdb?

What is hot spotting? "Hot spotting" in this context means that, even though tempdb has multiple files, all the I/O work is being done in a single file. If tempdb is busy enough to justify adding ...
Aaron Bertrand's user avatar
15 votes
Accepted

How to Move TempDB Files to a Different Drive or Folder?

Moving the TempDB files is a 2-step process: Tell SQL where you want your new TempDB files to go to Restart the SQL Server service for the change to take effect To tell SQL where to create the new ...
Oreo's user avatar
  • 1,554
14 votes
Accepted

Sort spills to tempdb but estimated rows equals to actual rows

Enable trace flag 7470. FIX: Sort operator spills to tempdb in SQL Server 2012 or SQL Server 2014 when estimated number of rows and row size are correct As I wrote in answer to Query Plan question: ...
Paul White's user avatar
  • 90.3k
13 votes
Accepted

How to clear temp database content in SQL Server?

If you truly feel you need to clear it, then yes, restarting SQL Server will clear it. However, that will likely be a temporary solution and you'll be back in the same condition after a few days. ...
Tony Hinkle's user avatar
  • 7,984
13 votes
Accepted

Why would shrinking TEMPDB log lead to slowness?

I'd ask the person who told you that, to at least hear why they think it will decrease performance. One reason is that your TLOG isn't going to stay at 0. Since you shrunk it so small, I presume you ...
S3S's user avatar
  • 3,588
12 votes
Accepted

SQL Server tempdb on RAM Disk?

First, patch: make sure you're on 2012 Service Pack 1 Cumulative Update 10 or newer. In SQL 2014, Microsoft changed TempDB to be less eager to write to disk, and they awesomely backported it to 2012 ...
Brent Ozar's user avatar
  • 43.2k
12 votes
Accepted

Why does truncating a temp table at the end of the stored procedure that creates it free tempdb space faster?

Truncating a temp table at the end of the stored procedure that creates it seems to cause the space the table uses in tempdb for the data to be released faster than if no truncate statement is used, ...
Paul White's user avatar
  • 90.3k
11 votes
Accepted

what is the best practice for tempdb autogrowth?

For me, the best practice is to just size the files large enough, at the outset, to accommodate the growths you expect. Let's use some simple numbers. Say you have a 100 GB drive that you've ...
Aaron Bertrand's user avatar
11 votes
Accepted

Given that CREATE PROCEDURE must be the first statement of its batch, what is the use of Temporary Stored Procedures?

common The most common uses I have for temporary stored procedures are: Skirting permissions and procedural issues Testing parameterized application queries Avoiding ASYNC_NETWORK_IO wait ...
Erik Reasonable Rates Darling's user avatar
10 votes

Query memory grant and tempdb spill

does that mean no matter how good the CE is, the query has no chance of not spilling over? since the query max ram is hard capped at 38 GB The overall memory grant for your query appears capped at ...
Paul White's user avatar
  • 90.3k
10 votes
Accepted

Tempdb Add files require Restart

ADD - no outage required. Although as Sean from Microsoft pointed out, SQL will prefer to use the lower filled files. If you are going from 1 data file and adding more, then SQL will use the new ...
Jonathan Fite's user avatar
10 votes
Accepted

Does LocalDB support temporary tables?

I can't answer for all versions, but for SQL Server 2012 up until SQL Server 2017 I am certain that they are supported LocalDB has the same programmability features as SQL Server Express. SQL ...
Randi Vertongen's user avatar
10 votes
Accepted

Sort spills to tempdb due to varchar(max)

There are going to be several possible workarounds here. You can manually adjust the memory grant, though I probably wouldn't go that route. You can also use a CTE and TOP to push the sort lower, ...
Forrest's user avatar
  • 4,179
10 votes

What is hot spotting in the context of adding files to tempdb?

What is hot spotting? Aaron is correct and I'm not going to rehash what he has said above, however it's not just about disk IO. The main part that most people have issues with in TempDB is due to ...
Sean Gallardy's user avatar
9 votes
Accepted

Tempdb approaching disk max: Is it OK to wait?

This isn't a big deal -- in fact, it's the way a lot of people handle tempdb in the first place: Add multiple data files Pre-size files equally to nearly fill tempdb drive Set autogrowth to a small ...
Erik Reasonable Rates Darling's user avatar
9 votes

Is it generally faster to select into a temp table than selecting into an actual table?

As well as writes to tempdb often not every hitting disk/network IO, as extended upon in David Browne's answer, depending on your IO configuration you may find that even when the data is big enough to ...
David Spillett's user avatar
9 votes
Accepted

SQL Server in-memory optmized tempdb metadata memory usage continually growing

Pam Lahoud SQL Enterprise Team Principal Program Manager at Microsoft said on twitter: and contributed via comment here: There are a few known issues that could be coming into play here. It's best ...
9 votes
Accepted

TempDB GAM contention for SELECT queries

The core of your issue is covered by the documentation in Recommendations to reduce allocation contention in SQL Server tempdb database. You're running SQL Server 2019, which means you'll see ...
Paul White's user avatar
  • 90.3k
9 votes
Accepted

how to kill a rogue spid that is already killed?

SPID 54: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds. Unfortunately there's not much one can do once a process begins rolling back other ...
J.D.'s user avatar
  • 39.5k
8 votes
Accepted

Allocate space for object 'dbo.SORT temporary run storage

This is pretty self explanatory - your tempdb is full, and can't be grown to perform the operation it needs tempdb for. As indicated, either the disk where it is located is full, or you haven't got ...
Ian_H's user avatar
  • 1,666
8 votes
Accepted

Recommendations for more than one tempdb file

We have various installations at our shop and we tend to start low with four tempdb files and then add additional files if there is tempdb contention as pointed out by @Kevin3nfs comment, where he ...
John K. N.'s user avatar
  • 18.3k
8 votes

Can multiple instances of procedure create same #Temp simultaneously?

"I cannot run multiple instance of this procedure simultaneously. Why?" Could you clarify what you mean by "cannot run"? Do you get an error? Now, you don't need to check the ...
SQLRaptor's user avatar
  • 4,098
8 votes

How to inspect global temp table from outside the transaction it is created in

Not really, no. The created, but uncommitted, global temporary table is protected by a schema-modification lock, which is incompatible with everything else, including the minimal schema-stability ...
Paul White's user avatar
  • 90.3k
8 votes
Accepted

Why does TempDB spill happen even though statistics are correct?

As the tooltip shows, 7643 8KB pages are spilled = 59.71MB. The rest of the sort occurs within the allocated memory. The sort spills for two reasons: The sort is parallel. The accurate memory ...
Paul White's user avatar
  • 90.3k
7 votes

Allocate space for object 'dbo.SORT temporary run storage

Run this command to get the estimated tempdb space required for the check: DBCC CHECKDB ('databasename') WITH ESTIMATEONLY See the DBCC CHECKDB documentation ESTIMATEONLY Displays the estimated ...
Sathishchandra BhanuMurthy's user avatar
7 votes

SQL Server tempdb on SSD showing IO

I would highly recommend that you test your new T:\ drive using Crystal Disk Mark. Check out the guide from Brent Ozar here: How to Test Your Storage with CrystalDiskMark Compare the results from ...
Josh Darnell's user avatar
  • 29.8k
7 votes

Sort spills to tempdb due to varchar(max)

Why are the spills only happening when [remark] is selected? The spill is happening when you include that column because you don't get a big enough memory grant for the large string data being sorted....
Josh Darnell's user avatar
  • 29.8k

Only top scored, non community-wiki answers of a minimum length are eligible