UrbanPro
true

Learn MS SQL from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What Is WorkTable In SQL Server?

Amitava Majumder
19/12/2017 0 0

What is WorkTable in SQL Server?

USE AdventureWorks2014

GO

SET STATISTICS IO ON

GO

SELECT *

FROM Production.Product p

CROSS JOIN Production.Product p1

GO

If you run above query, there is good chance that it will give you following details in the message windows.

Table ‘Product’. Scan count 2, logical reads 30, physical reads 1, read-ahead reads 17, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table ‘Worktable‘. Scan count 1, logical reads 8110, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

You will notice in the message there is a table called worktable. However, if you see the original table there is no worktable. This is where the question has originated.

The question in another word is, "Why does statistics show the worktable where it is not there in the original query?"

Well, the answer is very simple, quite often SQL Server has to perform any logical operations for any specific queries and to perform these logical operations SQL Server has to build a worktable. Worktables are built in tempdb and are dropped automatically when they are no longer needed.

Worktables:

The relational engine may need to build a worktable to perform a logical operation specified in an SQL statement. Worktables are internal tables that are used to hold intermediate results. Worktables are generated for certain GROUP BY, ORDER BY, or UNION queries. For example, if an ORDER BY clause references columns that are not covered by any indexes, the relational engine may need to generate a worktable to sort the result set into the order requested. Worktables are also sometimes used as spools that temporarily hold the result of executing a part of a query plan. Worktables are built in tempdb and are dropped automatically when they are no longer needed.

0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

An Introduction to Business Intelligence Concepts
Looking for a Business Intelligence (BI) solution for your company can be intimidating. BI uses its own special terminology and the database design concepts can be difficult to grasp. So where do you...

What Are Olap, Molap, Rolap, Dolap, Holap?
1. OLAP: On-Line Analytical Processing: Designates a category of applications and technologies that allow the collection, storage, manipulation and reproduction of multidimensional data, with the goal...

10 Best Job Interview Tips for Jobseekers
10 Best Job Interview Tips for Jobseekers:- 1. Conduct Research on the Employer, Hiring Manager, and Job Opportunity2. Review Common Interview Questions and Prepare Your Responses3. Dress for Success4....

SQL INSERT into Statement
SQL INSERT INTO Statement The INSERT INTO statement is used to insert new records in a table. The SQL INSERT INTO Statement The INSERT INTO statement is used to insert new records in a table. SQL INSERT...

DBMS (Database Management System) Vs RDBMS ( Relational Database Management System)
DBMS RDBMS Stored data in a file Stored data in a table As it is stored in a file, there is no relationship concept Data in one table may be relationship with data in another table...
X

Looking for MS SQL Classes?

The best tutors for MS SQL Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn MS SQL with the Best Tutors

The best Tutors for MS SQL Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more