sql语句格式化工具

在事件探查器跟踪到的sql语句非常的难以读懂,找了很久才找到几个合适的工具来格式化sql语句。

1.sql pretty printer :
   用起来感觉不错,但找不到注册key,只能转换50行,有限制,可惜,不知道有key的兄弟能不能给我发一个。

2. Toad for SQL Server 3.1 Freeware
   这个新建sql语句到是蛮好,也带了查询分析器,但似乎不能够将现成的sql语句格式化。

3.vim+sql 格式化脚本
  完全免费的组合
看个官方的列子

Examples:
                                                                            
  Original:
  SELECT m.MSG_ID, m.PRIORITY_ID, CUST.CUST_NBR, CUST.CUST_NM,
  CUST.CUST_LEGAL_NM, CUST.STORE_ADDR_1, CUST.STORE_ADDR_2,
  CUST.CROSS_STREET, XMLELEMENT( 'Alerts', XMLELEMENT( 'Alert_alert_id',
  alert_id ), XMLELEMENT( 'Alert_agent_id', agent_id ), XMLELEMENT(
  'Alert_alert_type_id', alert_type_desc), XMLELEMENT(
  'Alert_alert_date', alert_date), XMLELEMENT(
  'Alert_url_reference', url_reference), XMLELEMENT(
  'Alert_read_status', read_status )) CUST.STORE_CITY,
  CUST.STORE_ST, CUST.POST_CODE, CUST.STORE_MGR_NM, FROM MESSAGES m JOIN
  PRIORITY_CD P WHERE m.to_person_id = ?  AND p.NAME = 'PRI_EMERGENCY' AND
  p.JOB = 'Plumber' AND m.status_id < ( SELECT s.STATUS_ID FROM
  MSG_STATUS_CD s WHERE s.NAME = 'MSG_READ') ORDER BY m.msg_id desc
  
                                                                            
  Formatted:
  SELECT m.MSG_ID, m.PRIORITY_ID, CUST.CUST_NBR, CUST.CUST_NM,
         CUST.CUST_LEGAL_NM, CUST.STORE_ADDR_1, CUST.STORE_ADDR_2,
         CUST.CROSS_STREET,
         XMLELEMENT(
             'Alerts', XMLELEMENT( 'Alert_alert_id', alert_id ),
             XMLELEMENT( 'Alert_agent_id', agent_id ),
             XMLELEMENT( 'Alert_alert_type_id', alert_type_desc),
             XMLELEMENT( 'Alert_alert_date', alert_date),
             XMLELEMENT(
                 'Alert_url_reference', url_reference
              ), XMLELEMENT( 'Alert_read_status', read_status )
         ) CUST.STORE_CITY, CUST.STORE_ST, CUST.POST_CODE,
         CUST.STORE_MGR_NM
    FROM MESSAGES m
    JOIN PRIORITY_CD P
   WHERE m.to_person_id = ?
     AND p.NAME = 'PRI_EMERGENCY'
     AND p.JOB = 'Plumber'
     AND m.status_id < (
          SELECT s.STATUS_ID
            FROM MSG_STATUS_CD s
           WHERE s.NAME = 'MSG_READ'
         )
   ORDER BY m.msg_id desc

你可能感兴趣的:(sql语句)