分类目录

链接

2024 年 4 月
1234567
891011121314
15161718192021
22232425262728
2930  

近期文章

热门标签

新人福利,免费薅羊毛

变量表与临时表的效率分析

昨日一朋友发来一段sql的存储过程(如下),让我看看能不能优化一下。 insert @T1 select g_no,co_no,si_no,str_no,sum(ind_qty) as qty from instock_detail where  in_id = @id  group by g_no,co_no,si_no,str_no--?unitstock  -->保存在变量表中 insert @T2 select a.* from  unitstock a,@T1 b where a.g_no =b.g_no  and a.co_no =b.co_no and a.si_no =b.si_no and a.str_no=b.str_nodelete unitstock from @T1 a where unitstock.g_no=a.g_no  and unitstock.co_no =a.co_no and unitstock.si_no=a.si_...

SQL Server 暂无评论 阅读(2,262)

临时表与union all的性能差别

机器:cpu: 2g 内存: 2g 数据库:sql 2005 根据机器配置不同,结果会有不同. 性能测试说明: 1. 数据库服务器重启之后进行查询.即第一次查询的结果. 2. 是对数据库查询的性能比较. 测试情况: 1.在存储过程中使用临时表: (proc1) select top 1000 * into #t1 from somast insert into #t1 select top 100 * from somast select * from #t1 ---删除表数据 TRUNCATE TABLE #t1 --删除临时表 drop table #t1 执行时间为: 1039ms 2. 在存储过程中使用union all: (proc2) select top 1000 * from somast union all select t...

SQL Server 暂无评论 阅读(2,284)