sql 创建表变量,临时表+表变量与临时表区别 (转)

基本原则:能用表变量就用表变量.实在不行才使用临时表
表变量主要是开销系统的内存,而临时表则使用tempdb.对于小数据量的中间数据存储,可以使用表变量,而当需要临时保存的数据很大时,建议使用临时表.

declare @table table(id int identity(1,1),tid int) --创建表变量
select * from @table

create table #table (id int identity(1,1),tid int) --创建临时表
select * from #table
drop table #table   --删除临时表

原文地址:https://www.cnblogs.com/dudu837/p/1781303.html