简体   繁体   中英

How do I pretty format my SQL query in DBeaver?

I use DBeaver for my main IDE to query multiple databases. When I query a table, it automatically generates a long select statement with all columns in one line.

When I am making more complex queries, this gets very cumbersome to work with and read. I would like to view the select values on separate lines rather than one long string.

Is there an easy way (perhaps by using Notepad++ or Sublime Text) to break up the query (with line breaks after the commas)?

For example,

select name, address, city, state, country, zip_code, birthday, membership_type 
from customers

to

select
name,
address,
city,
state,
country,
zip_code,
birthday,
membership_type
from customers

DBeaver has a shortcut for this purpose. In SQL Editor: 在此处输入图片说明

Yes there is. I use Notepad++ because it is free and I use it for everything! Anyways, Notepad++ has a Plugin called: Poor Man's T-SQL Formatter. It works with a click of a button. You also get a few custom options like if you want to auto capitalize table names, etc.

在此处输入图片说明

Select a query to be formatted and Ctrl + shift + F does the work. I am using DBeaver 6.3.0

there is another plugin for formatting SQL in Notepad++. It can be found here: SQLinForm SQL Formatter and has 100+ formatting options with code folding and color formatting. There is also a free plugin available.

SQLinForm SQL 格式化程序

In SublimeText I assume you have already installed Package Control ? If not do so as soon as you can, it is a vital tool.

From Package Control there are a number of options to do what you want to do. Here are some options

I would start with SqlBeautifier and then try others to find which one suits your taste best.

使用反引号 ` 代替引号 " 或 '

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM