【发布时间】:2012-12-06 00:39:51
【问题描述】:
我正在尝试加快我的存储过程怪物的速度,该过程适用于许多表中的数百万条记录。
我偶然发现了这个: Is it possible to use a Stored Procedure as a subquery in SQL Server 2008?
我的问题是为什么使用表值函数比使用临时表更好。
假设我的存储过程@SP1
declare @temp table(a int)
insert into @temp
select a from BigTable
where someRecords like 'blue%'
update AnotherBigTable
set someRecords = 'were blue'
from AnotherBigTable t
inner join
@temp
on t.RecordID = @temp.a
在阅读了上面的链接之后,似乎 consunsus 不是使用我的 @temp 作为临时表,而是创建一个表值函数来执行该选择。 (如果它是一个简单的选择,就像我在这个例子中一样,则内联它)但是我的实际选择是多个并且通常不简单(即带有子查询等) 有什么好处?
谢谢
【问题讨论】:
标签: sql stored-procedures stored-functions