-
Notifications
You must be signed in to change notification settings - Fork 13
SQL Coding Standard and Guideline
Formatting refers to the indentation, alignment, and use of white space to lay out your SQL script to increase its readability by others.
Consistency is the key to producing readable code. While many can argue to merits of 3 versus 4 spaces of indentation, placement of parenthesis, etc., the real key is to adopt a formatting style and keep to it.
In the real-world, organizations adopting a standard for formatting increase programmer productivity by reducing variations and trivial decisions among teams of programmers. By following formatting standards, DBA and SQL developers do not need to individually decide on the relatively trivial matters of formatting. Instead, they can spend their time and energy on the harder problems of the code solution.
-
-
这个列表中的参数目前并没有实现,以后作为统一参数提供给用户使用。参数的格式
fmtnnn
,形如fmt001
-
这个列表中的参数目前并没有实现,以后作为统一参数提供给用户使用。参数的格式
-
- 以
gfmtopt
开头的格式化参数是目前在 delphi 版本的 SQL Pretty Printer 中实现的,会提供对应的 DLL 文件功能调用。
- 以
-
- GSP library Java 版本也实现了一个 SQL Formatter, 里面的格式化参数在
GFmtOpt
中,需要和 delphi 版本的gfmtopt
参数对应起来。
- GSP library Java 版本也实现了一个 SQL Formatter, 里面的格式化参数在
-
- 因为历史的原因,现在我们需要通过一个 SQL Formatter gateway 程序,把 delphi 版本的 SQL Pretty Printer (以DLL的形式提供) 和 GSP library Java 版本 SQL Formatter 整合起来,根据情况,调用二者之间的其中一个,给用户提供 SQL formatter 服务。
-
- 基于第4点的原因,我们先整理 DLL 和 Java 版本的 格式化参数,把功能相同的格式化参数整理出来放在本文档中。
-
- 提供给最终用户使用的是 第1步中列出的这些参数,然后根据实际调用的是 DLL 还是 Java的程序,把参数翻译成对应的DLL 和 Java 需要的参数。
-
- 以
gfmtopt
参数为基础进行梳理,列出对应的GFmtOpt
参数和fmtnnn
, 后两者如果没有找到,可以先空着。
- 以
-
-
参数类型的梳理,参考Align option, 这部分已完成,见这里
-
-
- 把本页中的每个以
gfmtopt
开头的格式化参数找到对应的页面(如果没有,新建一个页面),参考这个, 该详情页面中需要包含 delphi, Java 和 Uniform三种参数, 并配上演示效果用的 SQL 语句,暂时没有的,可以写上 TODO。
- 把本页中的每个以
- Alignments
- BlankLines
- Capitalisation
- Case Expression*
- Comments*
- Create table*
- CTE*
- Declare*
- Default option*
- Execute*
- Expression*
- Identation
- Insert*
- Line number*
- Line width*
- Parameter*
- Refactor*
- Select*
- Subquery*
- Syntax highlighting*
- Update*
- Whitespace
- Output Type*
- Preprocessor*
- Generic rules
- PL/SQL vertical spacing best practices standards
- No blank lines between continuously SQL Server set statement
- Add a blank line after SQL Server GO statement
- SQL fuction BEGIN/END keyword
- SQL block with or without BEGIN/END keyword
- If statement
- PL/SQL exception
- Select List
- Into clause
- From clause
- From clause(join)
- Where clause
- Group by clause
- Having clause
- Order by clause
- Select as subquery
- Padding
- PL/SQL operators and keywords
- Space around operator of arithmetic expression
- Spaces precede and follow character(') literals
- Space inside parenthesis of parameter definition of create function/procedure
- Space inside parenthesis of expression
- Space inside parenthesis of subquery
- Space inside parenthesis of function call
- Space inside parenthesis of type name specification of create table statement