易截截图软件、单文件、免安装、纯绿色、仅160KB

sql临时表

请教Sql #table ##table 和declare @tb table 的区别
##table 是全局的

#table为临时变量
##table为全局变量

Declare @tb table,这个嘛,有人说用临时表的效率快点,偶也弄不明白

前者是表
後者是變量

问题相应的这么快 谢谢


引用
#table为临时变量
##table为全局变量
Declare @tb table  创建一个变量表


全了。lz参考!

找到答案了

基本原则:能用表变量就用表变量.实在不行才使用临时表
表变量主要是开销系统的内存,而临时表则使用tempdb.对于小数据量的中间数据存储,可以使用表变量,而当需要临时保存的数据很大时,建议使用临时表.
declare @tb table(id int,name varchar(50),age int) --创建表变量

insert @tb 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 --删除临时表


实例
------------------------------------------------------------------ ----------------------------

declare @tab table
(
    id int,
    name nvarchar(50)
)
insert into @tab(id,name)
select person_id,1 from perso


相关问答:

sql 存储过程

我要做一个定点事件,是每天晚上12点就把三个表里的信息放入一个表里,我想用存储过程来写,怎么写呢?,那位高手帮帮忙吧,非常感谢!

用户名是唯一的
表A  字段
用户名:Name  ,邮箱:Ema ......

sql 搜索语句 - .NET技术 / ASP.NET

<table style="width: 1000px"><tr>
  <td style="height: 38px; width: 35px;">
  姓名</td>
  ......

C#和数据库SQL - MS-SQL Server / 基础类

我们C#做一个窗体 往数据库里插入数据
  SqlConnection cn = new SqlConnection("Data Source=20090713-1752\\SQLEXPRESS;Initial Catalog=goods;Integrated Security=True");
  ......

一个pl/sql问题 - Oracle / 开发

我是在toad中输入下段sql
  declare
  TYPE test_rec IS record(
  code varchar(10),
  name varchar(30)
  );
  v_book test_rec;
    ......

求一sql语句 - MS-SQL Server / 基础类


id bh  
1 10
2 11
3 12 
4 15
5 16
6 22
7 25
8 26
9 27
10 28
将bh按连续分段出来返回字符串:
10~12,15~16,22,25~28
SQL code:


declare @t tabl ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号