博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最详细的临时表,表变量的对比
阅读量:6266 次
发布时间:2019-06-22

本文共 1685 字,大约阅读时间需要 5 分钟。

Feature

Table Variable

Temp Table

Note

Table Name

Max 128 characters

Max 116 characters

 

Data Storage

In memory and TempDB

TempDB

 

Meta Data

In memory

TempDB

A table variable inherits current database settings and can use the registered UDTs, user defined data types, and xml collections in the database. A temp table inherits the settings of TempDB and cannot use the types created in the user database if the same types do not exist in the TempDB.

Scope

Current batch

Current session

Temp tables created in a stored procedure (SP) can be referenced by dynamic queries in the SP, sub SPs, triggers fired by the affected tables of the SP.

Constraints

Allowed

Allowed

For table variables, since no DDL is allowed, constraints can not be created in separate DDL statements.

DDL

Not allowed

Allowed.

E.g. create Index on the temp table.

Concurrent

Supported

Supported

Constraints and Indexes with explicit name in a temp table cause duplicate name error.

Statistics

Not supported

Supported

Estimated row number in execution plan for table variable is always 1

Parallel execution plan

Supported only for select

Supported

Parallel query execution plans are not generated for queries that modify table variables.

Transaction and Locking

Not participated

Participated

Data in table variable is not affected if the transaction is rolled back

Cause Recompile

No

Yes

Temp Table creation causes SPs/batches to recompile

SELECT INTO <t>

Not supported

Supported

 

INSERT <t> EXEC

Not supported

Supported

 

Use

UDFs, Stored procedures, Triggers, Batches

Stored procedures, Triggers, Batches

 Temp tables can't be used in UDFs.

 

from:http://www.sqlservercentral.com/articles/Table+Variables/63878/

 

Very Good~

转载地址:http://tidpa.baihongyu.com/

你可能感兴趣的文章
aaronyang的百度地图API之LBS云与.NET开发 Javascript API 2.0【基本地图的操作】
查看>>
Java Nio 多线程网络下载
查看>>
C++不让程序一闪而过
查看>>
C# 中的枚举类型 enum (属于值类型)
查看>>
[Debug] Use Snippets to Store Behaviors in Chrome DevTools
查看>>
【Java面试题】3 Java的"=="和equals方法究竟有什么区别?简单解释,很清楚
查看>>
通用性好的win2003序列号: (推荐先用这个里面的)
查看>>
Chromium Embedded Framework中文文档 (升级到最新的Chrome)
查看>>
WPF Command CanExecute 的执行逻辑
查看>>
更为快捷的Excel操作方式 快捷键 Alt使用技巧动画图解
查看>>
程序员们最易犯的10种错误
查看>>
面试必考题!你知道CSS实现水平垂直居中的第10种方式吗?
查看>>
超多惊喜!苹果 iPhone8 最新渲染图曝光
查看>>
你想要不想要?OPPO R11将搭配前后2000万像素镜头!
查看>>
Payara基金会发布全面支持MicroProfile 2.0的5.183版
查看>>
360金融宣布采用新会计准则 2018年前三季度净利11亿
查看>>
非洲小哥见到马云 竟然提了这样的要求?
查看>>
收购大战:高通承诺将年收入增长率提至8%
查看>>
宁夏:科技创新激活高质量发展动能
查看>>
毕马威:中国消费未现降级 进一步增长潜力巨大
查看>>