Creating Temporary Tables

The first advanced topic we discuss is the use of temporary tables, which are simply tables that exist temporarily within a database and are automatically dropped when users log out or their database connection ends. Transact-SQL creates these temporary tables in the TEMPDB database. This database is created when you install a SQL server. Two types of syntax are used to create a temporary table, as follows:

SYNTAX 1:
create table #table_name (
field1 datatype,
.
.
.
fieldn datatype)

Syntax 1 creates a table in the TEMPDB database. This table is created with a unique name consisting of a combination of the table name used in the CREATE TABLE command and a date-time stamp. A temporary table is available only to its creator. ...

Get Sams Teach Yourself SQL in 21 Days, Fourth 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.