两者都是常用的存储数据方式 。
•
从性能角度对比两者,可以概括为两点
:
--
表变量的操作都会在独立的
transaction
中立即
commit
,大大减少了锁定资源的需求
--因为表变量是无统计信息的。 所以存储过程不会因为表变量的数据量变化而重编译 。
实验证明如下:
begin tran
declare @i int
insert into @i select 2
select * from sys.dm_tran_locks ;
rollback ;
go
begin tran
craete table # (id int )
insert into # select 2
select * from sys.dm_tran_locks ;
rollback ;
go
-------实验结果可见 :表变量大大减少了锁定资源的操作 。