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

Statistics on temp table Expand / Collapse
Posted Thursday, January 2, 2014 9:23 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 25, 2014 11:59 AM
Points: 323, Visits: 1,465
From what I've read, temp tables do have statistics on them. Would SQL Server create its own on them if you don't have an index on the table? Like the _WA_Sys ones.They're tough to find and DBCC ShowStatistics requires a statistic name.

This could be a red herring as I don't see a lot of folks asking about this.

Post #1527185
Posted Thursday, January 2, 2014 9:46 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 11:49 AM
Points: 288, Visits: 1,166
Grant Wrote a wonderful article on statistics early this year, explaining stats on Temp Tables/Variables.

From his article:
Are statistics created on temporary tables?
Yes. The major difference between a table variable and a temporary table is that a temporary table has statistics. The rules for the creation and maintenance of these statistics are exactly the same as for a regular table within SQL Server. So if you reference a column in a temporary table in a filtering command in T-SQL such as WHERE or JOIN, then a set of statistics will get created. Unfortunately, the creation of the statistics causes a statement recompile. This is a potential disadvantage of temporary tables: For small statements this is a cheap operation. For larger queries this can be very expensive. That’s a reason why you have to be careful about how you work with your temporary tables.

You can find his full article(where I got this info) here for more details on Statistics:
Post #1527196
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse