SQL格式化插件—SQL Pretty Printer
我们编写的SQL脚本,例如存储过程和函数等,由于在编写过程中,我们需要手动美化SQL增加可读性,需要经常调整列名,注释以及AS,要我们手动空格,费时又费力。而且手动对代码进行格式化,如果代码脚本比较多,例如JION的表比较多,那需要调整的就更多了,有这个时间我们可能又写了几段SQL,那么问题来了,如何快速对SQL Server中的代码进行格式化。
有一个工具 SQL Pretty Printer,是一个SQL 管理工具的插件,功能非常强,格式化SQL代码效果很好,还可申请免费注册码,就下载下来试用了一下,感觉非常不错。这里给大家分享一下。
下载并安装SQL Pretty Printer Add-In for SSMS V3.6.1 后,在SQL Server 2008 管理工具中可以看到SQL Beautifier的菜单:
例如我们原本的代码
select
unix_timestamp() as etl_time, --时间
order_id as order_id,
app_id as app_id, --ID
status as status,
coupon_id as coupon_id,
coupon_deduct_amt as coupon_deduct_amt,
coupon_status as coupon_status
from stg_xyz_app_order_link_ed a --表名
where dt = '20200105';
格式化之后,我们不仅对齐了as列 而且使每个字段加入了我们的列名,简直是非常方便了
select unix_timestamp() as etl_time, --时间
a.order_id as order_id,
a.app_id as app_id, --ID
a.status as status,
a.coupon_id as coupon_id,
a.coupon_deduct_amt as coupon_deduct_amt,
a.coupon_status as coupon_status
from stg_xyz_app_order_link_ed a --表名
where a.dt = '20200105';
是不是非常规整,漂亮呢?!
SQL Pretty Printer目前提供4种使用方式,桌面版本,SSMS(SQL Server Management Studio)插件,VS插件,和提供API接口。
下载链接:http://www.dpriver.com/dlaction.php
在线版本(不支持中文):http://www.dpriver.com/pp/sqlformat.htm
获取免费的授权码:http://www.dpriver.com/products/sqlpp/getforfree.php