您现在的位置是:首页 > 电脑 > 

[col] in('single element')和[col] ='single element'之间有什么区别?(Any difference between [col] in ('single element') and [col] = 'single element'?)

2025-07-21 15:26:45
[col] in('single element')和[col] ='single element'之间有什么区别?(Any difference between [col] in ('single element') and [col] = 'single element'?) 我正在重构一个同事的旧SQL代码,并在一些地方注意到某个形式的where子句, w
[col] in('single element')和[col] ='single element'之间有什么区别?(Any difference between [col] in ('single element') and [col] = 'single element'?)

我正在重构一个同事的旧SQL代码,并在一些地方注意到某个形式的where子句, where [SomeCol] in ('XYZ') 。 我假设这只是代码中其他地方快速复制粘贴的结果,括号中有更多值( where [SomeCol] in ('ABC', 'DEF', 'XYZ') )并替换它们用[SomeCol] = 'XYZ' ,即使只是为了整洁。

只是想绝对确定这两个陈述在功能上是等同的 - 我会假设[SomeCol] = 'XYZ'有点(可能是不可靠的)更有效率,但我不想稍后发现我绊倒了一些不起眼的功能会产生不同的结果。

I'm refactoring a collegues' old SQL code and noticed in a few places a where clause of the form where [SomeCol] in ('XYZ'). I'm assuming that this is just a result of quick copy-paste from other places in the code with more values in the brackets (where [SomeCol] in ('ABC', 'DEF', 'XYZ')) and replacing them with [SomeCol] = 'XYZ', even if only for the sake of neatness.

Just wanted to be absolutely sure though that the two statements are functionally equivilant - I would assume that [SomeCol] = 'XYZ' is a little (likely unoticably) more efficient, but don't want to find out later I'm tripping over some obscure functionality that will produce different results.

最满意答案

它们在操作上应该是相同的。 当我在开始时只有一个值但我怀疑将来可能需要其他值时,我有时会完成I。 这样可以更轻松地添加新值而无需更改语句的结构。 只是猜测“为什么”。

They should be the same operationally. I've sometimes done the I when I had a single value at the start but suspected in the future other values could be required. That makes it easier to add the new values without changing the structure of the the statement. Just a guess at the "why".

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/61864.html

相关标签:无
上传时间: 2023-04-21 00:31:20
留言与评论(共有 12 条评论)
本站网友 江苏数字信息产业园
2分钟前 发表
'DEF'
本站网友 喜玛拉雅中心
15分钟前 发表
这样可以更轻松地添加新值而无需更改语句的结构
本站网友 pifu
3分钟前 发表
我有时会完成I
本站网友 联想k800跑分
8分钟前 发表
即使只是为了整洁
本站网友 桂林美食
16分钟前 发表
但我不想稍后发现我绊倒了一些不起眼的功能会产生不同的结果
本站网友 海龟交易法
0秒前 发表
I'm refactoring a collegues' old SQL code and noticed in a few places a where clause of the form where [SomeCol] in ('XYZ'). I'm assuming that this is just a result of quick copy-paste from other places in the code with more values in the brackets (where [SomeCol] in ('ABC'
本站网友 驻马店房产信息网
17分钟前 发表
'DEF'
本站网友 何超雄
13分钟前 发表
but don't want to find out later I'm tripping over some obscure functionality that will produce different results. 最满意答案 它们在操作上应该是相同的
本站网友 晋级潜艇
24分钟前 发表
They should be the same operationally. I've sometimes done the I when I had a single value at the start but suspected in the future other values could be required. That makes it easier to add the new values without changing the structure of the the statement. Just a guess at the "why".
本站网友 龙岩拍婚纱照
15分钟前 发表
并在一些地方注意到某个形式的where子句
本站网友 乡镇企业局
27分钟前 发表
'XYZ')) and replacing them with [SomeCol] = 'XYZ'