SQL Server 2008查询编辑器更改查询逻辑(SQL Server 2008 Query Editor changes the query logic)

编程入门 行业动态 更新时间:2024-10-25 22:30:54
SQL Server 2008查询编辑器更改查询逻辑(SQL Server 2008 Query Editor changes the query logic)

我在SQL Server 2008中手动编写了一个简单的SQL,如下所示:

SELECT * FROM Tab1 WHERE A='1' AND (B='1' OR C='1');

懒惰,我在查询编辑器中打开此查询来验证语法,并在对话框上按下确定,而不做任何更改。

我注意到查询编辑器已将我的查询更改为:

SELECT * FROM Tab1 WHERE A='1' AND (B='1') OR (C='1');

显然这会改变SQL的逻辑并根据执行的是哪个返回不同的结果。

我经常使用查询编辑器来验证我的复杂查询语法。 所以有一点担心,像这样的微妙变化会变得无足轻重,但会改变结果。

这是设计师的功能吗? 我能做些什么来改变这种行为吗?

编辑:谢谢指出编辑器所做的更改与上面不完全相同,但仍然查询被修改,虽然结果是相同的。

谢谢

I hand coded a simple SQL in SQL Server 2008 as below;

SELECT * FROM Tab1 WHERE A='1' AND (B='1' OR C='1');

Being lazy I opened this query in the Query Editor to validate the syntax and pressed OK on the dialog without making any changes.

I noticed that the Query Editor had changed my query to:

SELECT * FROM Tab1 WHERE A='1' AND (B='1') OR (C='1');

clearly this changes the logic of the SQL and returns different results depending on which one you execute.

I routinely use the Query Editor to validate my syntax on complex queries. So a little worried that the a subtle change like this would go unotice, but would change the outcome.

Is this a feature of the designer? Is there something I can do to change this behavior?

EDIT: Thanks for pointing out that the changes made by the editor is not quite the same as above, but still the query is modified although the results are the same.

Thanks

最满意答案

我试图在查询设计器中进行复制,结果稍有不同。 我输入了和你一样的内容:

SELECT * FROM Tab1 WHERE A='1' AND (B='1' OR C='1');

得到这个:

SELECT * FROM Tab1 WHERE (A = '1') AND (B = '1') OR (A = '1') AND (C = '1')

我不得不说结果是一样的,但我们都可以在这里看到一条危险的道路。 另外,我不喜欢(A = '1')复制。 哎呀,我想要的代码是如何编码的!

智者一句话:我从不在SQL Server Management Studio中格式化查询。 你有没有看到它对你的视图的代码做了什么? 我讨厌它。 我只是在其他地方编码并在完成时粘贴SMS。

I tried to replicate this in the Query Designer and had a slightly different result. I typed the same as you:

SELECT * FROM Tab1 WHERE A='1' AND (B='1' OR C='1');

And got this:

SELECT * FROM Tab1 WHERE (A = '1') AND (B = '1') OR (A = '1') AND (C = '1')

I have to say that the result is the same, but we can all see a dangerous road here. Also, I did not like the (A = '1') replication. Heck, I want the code how I coded it!

A word to the wise: I never format my queries in SQL Server Management Studio. Have you seen what it does to your view's code? I hate it. I just code somewhere else and paste in SMS when done.

更多推荐

本文发布于:2023-08-02 14:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1376971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   逻辑   Server   SQL   Editor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!