📜  sql server:哈希表和使用声明关键字声明的表之间的区别 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:04:54.084000             🧑  作者: Mango

代码示例1
There are quite differences like below.
1. Declarations: Table variables are declared as normal variables with type as table and columns along with their datatype.
whereas hashtables are created just like the normal tables.
Eg. i) Table Variable:  Declare @tmpTable as Table(id Int, Name Varchar(500), Salary Decimal)
    ii) Hashtable: Create Table(id Int, Name Varchar(500), Salary Decimal);

2. Next differences are where they are stored like Table variables are in Memory and Hashtables in tempdb.
3. As Hashtables are just like normal tables you can use them in transactions whereas not the table variables.
4. You can create indexes on Hashtables but not on table variables except the primary key indexes.
5. It's best to use table variables when you have small to moderate data to handle because of their better performance, as they reside in the memory.