Skip to content

SQL Coding Standard and Guideline

Tako Lee edited this page Mar 3, 2024 · 153 revisions

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.

格式化参数的说明

    1. 这个列表中的参数目前并没有实现,以后作为统一参数提供给用户使用。参数的格式fmtnnn,形如 fmt001
    1. gfmtopt 开头的格式化参数是目前在 delphi 版本的 SQL Pretty Printer 中实现的,会提供对应的 DLL 文件功能调用。
    1. GSP library Java 版本也实现了一个 SQL Formatter, 里面的格式化参数在 GFmtOpt 中,需要和 delphi 版本的 gfmtopt 参数对应起来。
    1. 因为历史的原因,现在我们需要通过一个 SQL Formatter gateway 程序,把 delphi 版本的 SQL Pretty Printer (以DLL的形式提供) 和 GSP library Java 版本 SQL Formatter 整合起来,根据情况,调用二者之间的其中一个,给用户提供 SQL formatter 服务。
    1. 基于第4点的原因,我们先整理 DLL 和 Java 版本的 格式化参数,把功能相同的格式化参数整理出来放在本文档中。
    1. 提供给最终用户使用的是 第1步中列出的这些参数,然后根据实际调用的是 DLL 还是 Java的程序,把参数翻译成对应的DLL 和 Java 需要的参数。
    1. gfmtopt 参数为基础进行梳理,列出对应的 GFmtOpt 参数和 fmtnnn, 后两者如果没有找到,可以先空着。
    1. 参数类型的梳理,参考Align option, 这部分已完成,见这里
    1. 把本页中的每个以 gfmtopt 开头的格式化参数找到对应的页面(如果没有,新建一个页面),参考这个, 该详情页面中需要包含 delphi, Java 和 Uniform三种参数, 并配上演示效果用的 SQL 语句,暂时没有的,可以写上 TODO。

SQL Server

Types of format option

Links

Clone this wiki locally