版本:DataGrip 2023.2.1
配置方法:Settings > Code Style > SQL > General(或其他語言)
Case 通用
Word Case 單詞大小寫設(shè)置
- Keywords:關(guān)鍵字大小寫設(shè)置(例如
SELECT
、WHERE
、AS
等) - Identifiers:標(biāo)識符大小寫設(shè)置(例如表名、列名等)
- Built-in types:內(nèi)置類型大小寫設(shè)置(例如
INT
、VARCHAR
等) - Custom types:用戶類型大小寫設(shè)置
- Aliases:別名大小寫設(shè)置
- Build-in functions:內(nèi)置方法的大小寫設(shè)置(例如
COUNT
、CASE
等) - Quoted identifiers:引用的標(biāo)識符(例如用引號括起來的表名、列名等)
- Use original case:
Quotation 引號設(shè)置
- Identifier quotation:標(biāo)識符前后的引號設(shè)置
- Unquote:去除標(biāo)識符前后的引號(但是當(dāng)已被引號括起來的標(biāo)識符中包含空格等字符時(shí),不會去除)
- Quote:在標(biāo)識符前后添加引號
- Quotation character:引號符號設(shè)置
Queries 查詢語句
Common:通用
- Align the first word of clause:是否將所有子句的左側(cè)對齊
- Place clause elements on :將子句放在關(guān)鍵字之后的什么位置
- Place comma:將每一行的逗號放置在什么位置(行首或行尾)(DataGrip 在將原本至于行首的格式化為行尾時(shí),會出現(xiàn)很多異常,很不穩(wěn)定
- Collapse short statement:是否折疊短的表達(dá)式
- Keep section elements under section header:
- Align section elements:
- Align line comments at right of elements:對齊每一行之后的注釋(在格式化之前,每行注釋之前必須有大于等于 1 個(gè)空格),包括字段后的注釋等
INSERT statements and VALUES clause:INSERT 表達(dá)式和 VALUES 字句
- Place INTO on the new line:將 INTO 關(guān)鍵字放到什么位置
- Place INTO clause elements on :
- Place VALUES clause elements (rows) on:
- Place the opening parenthesis:
- Place columns or values:
- Place the closing parenthesis:
- Wrap columns or values:
- Place comma:
- Spaces within parentheses:
- Collapse short multi-row values:是否折疊短的多條待插入數(shù)據(jù)
UPDATE statement:UPDATE 表達(dá)式
- Place elements on:
- Wrap elements:
- Place comma:
- Align
=
:是否將各個(gè)字段的=
對齊
WITH clause:WITH 字句
- Place elements on:
- Wrap subqueries:
- Place comma:
- Align AS:是否將各個(gè)中間表的
AS
對齊
SELECT clause:SELECT 字句
- Place elements on:
- Wrap elements:
- Place comma:
- New line after ALL, DISTINCT:
- Keep elements on the one line if <=:
- Use AS:是否使用
AS
或省略 - Align AS:是否對齊所有的
AS
- Treat asterisk as a regular element:
FROM caluse:FROM 字句
- Place elements on:第一個(gè)表名是跟在 FROM 關(guān)鍵字之后還是另起一行
- Wrap elements:FROM 字句是否換行
- Place comma:多個(gè)表時(shí)逗號的位置
- Wrap the first JOIN:第一個(gè) JOIN 字句是否換行
- Wrap the next JOIN:除第一個(gè)外的其他 JOIN 字句是否換行
- ident JOIN:在每個(gè) JOIN 字句前是否加額外的空格
- Place JOIN in join-only queries under
- Align joinedtables:是否對其每 join 字句中的表名
- Align table aliases:
- Wrap ON/USING:是否在 ON 和 USING 之前換行
- Place ON/USING under:如果 Wrap ON/USING 開啟的話,將 ON/USING 語句與什么對齊
WHERE and HAVING clauses:WHERE 和 HAVING 字句
- Place elements on:第一個(gè) WHERE 條件是跟在 WHERE 關(guān)鍵字之后還是另起一行
- Wrap elemnts:括號中的條件是否換行?
- Place top-level AND / OR:如何防止最上一層的 AND 和 OR 關(guān)鍵字
- begin:每行的開頭位置
- end:每行的結(jié)尾位置
GROUP BY and ORDER BY clauses:GROUP BY 和 ORDER BY 字句
- Place elements on:
- Wrap elements:
- Place comma:
- Align ASC / DESC:
Subquery:子查詢
-
Place the opening parenthesis:如何放置子查詢的左括號
-
Place subquery:如果放置子查詢的主體(即 SELECT 關(guān)鍵字)
-
Place the closing parenthesis:如何放置子查詢的右括號
- Under opening:與左括號的列對齊(新起一行)
-
Space after keyword:在子查詢前的關(guān)鍵字(例如 FROM、IN、EXISTS) 之后是否添加空格文章來源:http://www.zghlxwxcb.cn/news/detail-812170.html
-
Spaces within parentheses:在子查詢的括號之間是否添加空格文章來源地址http://www.zghlxwxcb.cn/news/detail-812170.html
DDL 數(shù)據(jù)定義語言
CREATE TABLE
- Place the opening parenthesis:如何放置左括號
- Place elements:
- Place the closing parenthesis:如何放置右括號
- Collapse when short:當(dāng)建表語句很短時(shí)是否折疊為一行
ALTER TABLE
- Wrap altering instructions:
- INdent altering instructions
- Align altering instructions
- Wrap altered items
- Indent altered items
- Align altered items
CREATE or ALTER TABLE
- Align types:是否對齊各個(gè)字段的類型
- Align defaults:是否對齊各個(gè)字段的
defaults
部分 - Align nullabilities:是否對齊各個(gè)字段的
NOT NULL
部分
CONSTRAINT
- Wrap CONSTRAINT:
- Wrap KEY/CHECK:
- Wrap REFERENCES:
- Wrap cascade and deferrability:
CREATE SCHEMA
- Indent content:
- Minimum blank lines between declaration
- Maximum blank lines between declaration
Views
- Wrap AS:是否對齊各個(gè)字段的 AS
- Wrap the beginning of the query:
- Indent query
Postfix options
- Wrap first option:
- Wrap next option:vpt
- Indent options:
- Align options:
Code
Script
- Wrap command-ending semicolon:
- Commands follow by blank lines:
Impreative Commons
- Wrap every statement
- Keep blank lines in code
Declared variables
- Wrap section
- Wrap variables
- Align types
- Align assignments
- Align expressions
Routine arguments
- Place the opening parenthesis
- Place elements
- Place the closing parenthesis
- Wrap elements
- Place comma
- Spaces within parentheses
- Align types
Routine statement
- Wrap AS
- Wrap opening
$$
- Wrap the content after opening
$$
- Wrap before closing
$$
- Wrap options after closing
$$
IF … THEN … ELSE
- Wrap
THEN
- Wrap
ELSE
- Wrap inner code
- indent
THEN
andELSE
- indent
END IF
- Collapse when short:當(dāng)整個(gè)
IF ... THEN ... ELSE
語句很短時(shí),是否折疊為一行
Loops
- Wrap
LOOP
- Indent
Loop
- Indent
END LOOP
- Collapse when short
Expressions
Cortege
- Add space before
(
- Space within parentheses
- Place comma to begin
- Space before comma
- Space after comma
Binary expression
- Use spaces around operators
- Align operands in binary expressions
- Space within parenthesized sub-expressions
Function or procedure call
- Space within parentheses
- Space before comma
- Space after comma
CASE clause:CASE 從句
- Wrap
WHEN
:是否在第一個(gè)WHEN
關(guān)鍵字之前換行 - Indent
WHEN
if wrapped:如果在第一個(gè)WHEN
關(guān)鍵字之前換行,是否在WHEN
關(guān)鍵字之前縮進(jìn) - Wrap
THEN
:是否在THEN
關(guān)鍵詞之前換行 - Align
THEN
:是否對齊THEN
關(guān)鍵字 - Align
ELSE
underTHEN
whenTHEN
aligned:如果THEN
關(guān)鍵字對齊,那么ELSE
是否與THEN
對齊(否則與WHEN
對齊) - Align
END
:如何將END
對齊 - Keep new line after
THEN
,ELSE
: - Collapse short clause:是否壓縮較短的 CASE 從句
Tabs and Indents
- Use tab character:是否使用制表符(
\t
) - Tab size:Tab(制表符)對應(yīng)的半角字符數(shù)
- Indent:縮進(jìn)的半角字符數(shù)
- Continuation indent
- Keep indents on empty lines
Wrapping
Keep when reformatting
- Line breaks
- Comment at first column
到了這里,關(guān)于DataGrip|SQL 自動(dòng)格式化常用配置(完整版)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!