Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server tables: what is the difference between @, # and ##?

Tags:

sql-server

In SQL Server, what is the difference between a @ table, a # table and a ## table?

like image 945
Craig Schwarze Avatar asked Feb 08 '10 05:02

Craig Schwarze


People also ask

What is the difference between #table and ## table in SQL?

#table refers to a local (visible to only the user who created it) temporary table. ##table refers to a global (visible to all users) temporary table.

How do you compare two tables in SQL?

Comparing the Results of the Two Queries Let us suppose, we have two tables: table1 and table2. Here, we will use UNION ALL to combine the records based on columns that need to compare. If the values in the columns that need to compare are the same, the COUNT(*) returns 2, otherwise the COUNT(*) returns 1.

How do you find the difference between two data in SQL?

SQL Server DIFFERENCE() Function The DIFFERENCE() function compares two SOUNDEX values, and returns an integer. The integer value indicates the match for the two SOUNDEX values, from 0 to 4. 0 indicates weak or no similarity between the SOUNDEX values.


3 Answers

#table refers to a local (visible to only the user who created it) temporary table.

##table refers to a global (visible to all users) temporary table.

@variableName refers to a variable which can hold values depending on its type.

like image 195
Arnkrishn Avatar answered Oct 13 '22 02:10

Arnkrishn


Have a look at

like image 28
Adriaan Stander Avatar answered Oct 13 '22 04:10

Adriaan Stander


# and ## tables are actual tables represented in the temp database. These tables can have indexes and statistics, and can be accessed across sprocs in a session (in the case of a global temp table, it is available across sessions).

The @table is a table variable.

For more: http://www.sqlteam.com/article/temporary-tables

like image 31
whiner Avatar answered Oct 13 '22 04:10

whiner