SQL Server caches temporary objects (temporary tables and table variables), that are created in a stored procedure. Temporary objects that are created either in dynamic SQL statement or by using sp_executesql are not cached. Temp table caching can lead to better performance by reducing Tempdb Allocation Contention. SQL Server will not cache temporary table in certain cases, for example, if a DDL operation is performed on the temporary table (dropping temporary table is not a problem), or if a named constraint is created on the temporary table.
The below video demonstrates this with hands-on example. SQLTest Tool simulates the hands-on labs for you, no registration necessary. You can practice the online hands-on example while watching the video.
Check out www.sqlvideo.com for additional hands-on videos.
Subscribe to our newsletter: https://newsletter.sqlworkshops.com