如何在 DBeaver 中漂亮地格式化我的 SQL 查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46429209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 05:19:54  来源:igfitidea点击:

How do I pretty format my SQL query in DBeaver?

sqlnotepad++sublimetext3sublimetextdbeaver

提问by Albert

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.

我使用 DBeaver 作为我的主要 IDE 来查询多个数据库。当我查询一个表时,它会自动生成一个长的 select 语句,其中所有列都在一行中。

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)?

是否有一种简单的方法(可能通过使用 Notepad++ 或 Sublime Text)来分解查询(在逗号后使用换行符)?

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

回答by NonProgrammer

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.

就在这里。我使用 Notepad++ 是因为它是免费的,而且我用它做任何事!不管怎样,Notepad++ 有一个插件叫做:Poor Man's T-SQL Formatter。它只需单击一个按钮即可工作。您还可以获得一些自定义选项,例如是否要自动大写表名等。

enter image description here

在此处输入图片说明

回答by Yurii Verbytskyi

DBeaver has a shortcut for this purpose. In SQL Editor: enter image description here

DBeaver 有一个用于此目的的快捷方式。在 SQL 编辑器中: 在此处输入图片说明

回答by Guido

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

在 Notepad++ 中有另一个用于格式化 SQL 的插件。可在此处找到:SQLinForm SQL Formatter并具有 100 多个带有代码折叠和颜色格式的格式选项。还有一个免费插件可用。

SQLinForm SQL Formatter

SQLinForm SQL Formatter

回答by jwpfox

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

在 SublimeText 中,我假设您已经安装了Package Control?如果不尽快这样做,它是一个重要的工具。

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

从包控制有许多选项可以做你想做的事情。这里有一些选项

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

我会从SqlBeautifier开始,然后尝试其他人来找到最适合您口味的。

回答by Nisarg Patil

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

选择要格式化的查询和Ctrl+ shift+F做的工作。我正在使用 DBeaver 6.3.0

回答by ParagDineshGupta

use backtick ` instead of quote " or '

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