0

我想从 3 个不同的表中返回 3 个单个值。

我想知道考虑到资源使用和性能(在存储过程中),这些代码中哪一个更好:

代码 1:

declare @acc_cnt int, @selected_item int, @worker_cnt int
select @acc_cnt=count(0) from accounts
select @selected_item=id from items where name='something'
select @worker_cnt=count(0) from workers
select @acc_cnt ,@selected_item,@worker_cnt

代码 2:

select count(0) from accounts
select id from items where name='something'
select count(0) from workers

返回 3 次选择和单次选择之间有区别吗?我正在使用 SQL Server 2008

4

1 回答 1

0

2 号将稍微提高性能,因为您没有声明变量并节省少量内存。

注意:性能改进几乎是不可估量的。

于 2012-05-08T05:40:33.830 回答