SQL语句缩进好做法 [英] SQL Statement indentation good practice

查看:1786
本文介绍了SQL语句缩进好做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

缩进SQL语句的常见做法是什么?例如,考虑以下SQL语句:

What is the accepted practice for indenting SQL statements? For example, consider the following SQL statement:

SELECT column1, column2
FROM table1
WHERE column3 IN
(
SELECT TOP(1) column4
FROM table2
INNER JOIN table3
ON table2.column1 = table3.column1
)

如何缩进?非常感谢。

推荐答案

SELECT column1
     , column2
FROM table1
WHERE column3 IN
(
    SELECT TOP(1) column4
    FROM table2
    INNER JOIN table3
    ON table2.column1 = table3.column1
)

我喜欢所有这种方式我从来没有搜索他们当X错误从SQL编辑器。

I like to have all "," in front, this way I never search them when an error at line X from the SQL editor.


SELECT sdcolumn123
 , dscolumn234
 , sdcolumn343
 , ffcolumn434
 , sdcolumn543
 , bvcolumn645
  vccolumn754
 , cccolumn834
 , vvcolumn954
 , cvcolumn104
FROM table1
WHERE column3 IN
(
    ...
)

SELECT sdcolumn123, dscolumn234, asdcolumn345, dscolumn456, ascolumn554, gfcolumn645 sdcolumn754, fdcolumn845, sdcolumn954, fdcolumn1054
FROM table1
WHERE column3 IN
(
    ...
)


$ b b

我发现第一个例子更容易和更快。希望这个例子向您展示我更多的观点。

I found easier and more quick at the first example. Hope this example show you more my point of view.

这篇关于SQL语句缩进好做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆