Stored Procedures and Temporary Tables

SQL Server creates temporary tables in a special system database called TempDB. SQL Server creates TempDB each time it starts and destroys it each time it shuts down. SQL Server uses TempDB to house many temporary objects that it needs to run. You can use TempDB to share data between procedures or to help you accomplish complex tasks. Many times you will need to incorporate temporary tables into the stored procedures that you write. Here's an example of how you create and use a temporary table:

 CREATE PROCEDURE procCustomersGetTemp AS BEGIN CREATE TABLE #TempCustomers (CompanyName varchar (50) NOT NULL PRIMARY KEY, ContactName varchar(50), ContactTitle varchar (50), City varchar (50)) INSERT INTO #TempCustomers ...

Get Alison Balter's Mastering Access 2002 Enterprise Development 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.