sql server - when - What is the meaning of “#” in front of a table name in TSQL?




when to use temp table in sql server (2)

#mytable is a temporary table where as mytable is a concrete table.

You can read more about Temporary Tables in SQL Server.

They are used most often to provide workspace for the intermediate results when processing data within a batch or procedure. They are also used to pass a table from a table-valued function, to pass table-based data between stored procedures or, more recently in the form of Table-valued parameters, to send whole read-only tables from applications to SQL Server routines, or pass read-only temporary tables as parameters. Once finished with their use, they are discarded automatically.

Temporary tables come in different flavours including, amongst others, local temporary tables (starting with #), global temporary tables (starting with ##), persistent temporary tables (prefixed by TempDB..), and table variables.(starting with (@)

what is the difference between the table names "#mytable" and "mytable" in TSQL? I see table names start with "#" in a lot of custom procedures.


These are local temporary tables which are private to the process that created them.







tsql