多选与单选语句 [英] Multiple Select vs Single Select Statement
问题描述
我只是想知道执行多次选择与使用一次选择之间的区别是什么?我看到有人这样做了,我觉得有点像下面这样;
I was just wondering whats the difference between doing multiple selects vs. using a single select is there any performance gain? I saw someone did it, and I feel its like kinda out of hand such as below;
select @a = cBranchName from mstores where nBranchCode = 1
select @b = cBranchAddress from mstores where nBranchCode = 1
select @c = dCreateDate from mstores where nBranchCode = 1
select @d = AssignedCompanyId from mstores where nBranchCode = 1
select @e = StoreFormat from mstores where nBranchCode = 1
vs.
select @a = cBranchName
,@b = cBranchAddress
,@c = dCreateDate
,@d = AssignedCompanyId
,@e = StoreFormat from mstores where nBranchCode = 1
我还假定5个select会进行5次访问数据库,如何证明单个select语句比5个select语句要快,
I also presume that the 5 select's make 5 trips to the database, how can I prove that single select statement is faster than the 5 select statements,
即使只是看一下,我已经认为单个选择语句比多个选择要快得多.
Even though just by looking at it, I already thought that the single select statement is significantly faster than the multiple selects.
推荐答案
主要区别:
- 五次往返,而不是一次.光/电的速度可以照顾到这一点
- 要检查,解析和执行5条语句(不是一个).您认为会更快些吗?
- 一致性-如果两次选择之间发生更新会怎样?
- 如果显示执行计划,您可以很清楚地看到正在进行的工作
我很茫然,无法理解为什么有人会认为5个查询比一个更好.
I'm quite at a loss to understand why anyone would ever have cause to think the 5 queries would be better than one.
这篇关于多选与单选语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!