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. ...