Skip to Main Content
Learn T-SQL Querying
book

Learn T-SQL Querying

by Pedro Lopes, Pam Lahoud
May 2019
Intermediate to advanced content levelIntermediate to advanced
484 pages
11h 23m
English
Packt Publishing
Content preview from Learn T-SQL Querying

Using table variables and temporary tables

Table variables and temporary tables serve the same basic purpose: to store an intermediate resultset to be used by a subsequent query. Database developers use these to break down complex joined queries that typically are not very efficient.

We have mentioned before how the way a query is written can severely compromise SQL Server's ability to optimize a query efficiently in the little time it has to do it.

This means that a complex T-SQL query can be broken down into simpler T-SQL statements that store intermediate results before being used to join with other tables. Imagine a developer needs to build a query in the AdventureWorks sample database that returns the sales quota data by year for each ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn T-SQL Querying - Second Edition

Learn T-SQL Querying - Second Edition

Pedro Lopes, Pam Lahoud
SQL Server T-SQL Recipes, Fourth Edition

SQL Server T-SQL Recipes, Fourth Edition

Jason Brimhall, Jonathan Gennick, Wayne Sheffield

Publisher Resources

ISBN: 9781789348811Supplemental Content