Using Temporary Tables for Storing Data

As you use T-SQL to perform more complex processing, you will sometimes need to temporarily save data that you have selected so that you can work with and possibly modify it. This is done using temporary tables. Temporary tables exist, as their name implies, for a limited amount of time. Temporary tables come in three variations: local, global, and permanent. All temporary tables are created in the TEMPDB database, no matter which database you are using when you create it.

Whenever you are processing a query, the SQL Server usually creates temporary tables behind the scenes as needed. When you use ORDER BY and the data you are sorting does not have an index associated with it, the server will use a temporary ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.