村长

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
基本原则:能用表变量就用表变量。实在不行才使用临时表。
如与动态语句结合、外部需要使用等,就需要临时表

表变量主要开销系统的内存,而临时表则使用tempdb。对于小数据量的中间数据存储,可以使用表变量,而当需要临时保存的数据量很庞大时,建议使用临时表。具体使用表变量还是临时表,可以根据系统的运行状况来调整。


declare @tb table(id int,name varchar(50),age int--创建表变量

insert @tb select 1,'nn',14
union all select 1,'nn',14

select * from @tb




create table #t(id int,name varchar(50),years int,nums int)--创建临时表
 insert #t select 1,'nn',14,15
union all select 1,'nn',14,15
insert into #t  exec sp_gets  --可以用于存储过程或动态SQL结合

select * from #t
drop table #t
文章出自:http://www.cnblogs.com/jierry/archive/2006/03/06/344251.html
posted on 2011-05-11 01:16  Say No  阅读(132)  评论(0编辑  收藏  举报