What does the SQL # symbol mean and how is it used?

Sql ServerSyntaxSymbols

Sql Server Problem Overview


Can someone please explain to me what the # symbol means in MS SQL Code.

I've tried Googling it, and even searching on StackOverflow, but can't seem to find the answer.

I feel like an idiot - having one of "those" days. Please help.

Sql Server Solutions


Solution 1 - Sql Server

They normally prefix temporary tables.

From the docs....

> Prefix local temporary table names > with single number sign (#table_name), > and prefix global temporary table > names with a double number sign > (##table_name).

Solution 2 - Sql Server

The pound sign # is used to prefix temporary tables and procedures. A single instance (#) refers to a temporary object that lives/dies with the current session while a double instance (##) is a global object.

Solution 3 - Sql Server

The other answers are correct if you're dealing with SQL Server, and it's clear that you are. But since the question title just says SQL, I should mention that there are some forms of SQL such as MySQL where a pound sign is used as an alternative commenting symbol.

#This is a comment.

https://dev.mysql.com/doc/refman/5.7/en/comments.html

Solution 4 - Sql Server

You could be seeing the # in the usage of a temporary table

SELECT
  *
FROM #myTempTable

Solution 5 - Sql Server

#TEMPTABLE. Its actually a type of a temporary table that is scoped for that session.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaajid IsmailView Question on Stackoverflow
Solution 1 - Sql ServerEd GuinessView Answer on Stackoverflow
Solution 2 - Sql ServerMichael HarenView Answer on Stackoverflow
Solution 3 - Sql ServerKyle DelaneyView Answer on Stackoverflow
Solution 4 - Sql ServerJohn HartsockView Answer on Stackoverflow
Solution 5 - Sql ServerBaajuView Answer on Stackoverflow