Using Temporary Tables in Stored Procedures

Temporary tables are commonly used in stored procedures when intermediate results need to be stored in a work table for additional processing. Local temporary tables created in a stored procedure are automatically dropped when the stored procedure exits. Global temporary tables created in a stored procedure still exist after the stored procedure exits until they are explicitly dropped (see Listing 44.12) or the user session in which they were created disconnects from SQL Server.

Listing 44.12 Using Local and Global Temporary Tables in Stored Procedures

image

Note what happens if you try to run the stored ...

Get Microsoft® SQL Server 2008 R2 Unleashed 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.