从最开始使用的notepad++到sublime,再到datagrip,发现最后一个功能更全一点,所以还是决定坚持用这个工具来格式化我的SQL。

      如果你懒得去自己一个个试,那么可以套用这个。

一、DataGrip的SQL格式化设置菜单

1.Preference(command+,)

2.Editor->Code Style->General 

二、格式化模板

1.Queries (查询)

注:未列举的选项均为 As in common/Do not change/不勾选

类别子类选项图例说明
Common(常见的)Align the first word of clause(对齐从句的第一个单词)To left类似于select from、where group by 这种主从句,关键字都是对齐的
Place clause elements on(将子句元素放在)Same line
Place comma(放置逗号)To begin逗号放前面不容易丢失
Collapse short statement(折叠简短声明)Do not change
Align line comments at right of elements(在元素右侧对齐行注释)☑️
INSERT statement and VALUES clausePlace INTO on the new line no
Put spaces within parentheses(将空格放在括号内) ☑️
WITH clauseAlign AS☑️
SELECT clauseWrap elementschop 
Align AS☑️
FROM clauseWrap the first JOIN☑️
Wrap the next JOIN☑️
Place JOIN in join-only queries underFROM indented
Align joined tables☑️
Wrap ON/USING☑️on 另起一行
Place ON/USING underTableon 和表名对齐
WHERE and HAVING clauseWrap elementschop 
Place top-level AND/ORTo begin
GROUP BY and ORDER BY clauseWrap elementschop 
SubqueryPlace SubquerySame line  aligned
Place the closing parenthesisTo begin
Put spaces within parentheses☑️

 2.Expressions(表达式)

 

 设置完这些代码已经呈现出比较整齐的状态了,后续还会更新。。。。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐