19

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
Yurii Verbytskyi
  • 1,962
  • 3
  • 19
  • 27
Albert
  • 267
  • 1
  • 3
  • 6

7 Answers7

32

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

Yurii Verbytskyi
  • 1,962
  • 3
  • 19
  • 27
  • To add here in case anyone else is struggling with this, I noticed that formatting of multiple sql statements doesn't work as expected if they don't have a semicolon after each of them. Once semicolons are added, it works great, as of version: 6.1.2.201907061627 – previouslyactualname Aug 26 '19 at 18:40
  • 2
    Best answer because it's not using any other tool apart from DBeaver – cpinamtz Mar 26 '20 at 16:31
13

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.

enter image description here

NonProgrammer
  • 1,337
  • 2
  • 23
  • 53
  • I'm wondering how to use this with DBeaver. I picked the external formatter option and put `"C:\Users\user\Downloads\SqlFormatter.1.6.10\SqlFormatter.exe" ${file}` in the command line. I'm using a temp file. I set the timeout to 10 seconds. It doesn't error, but it doesn't format either. – Frantumn Mar 07 '23 at 14:57
  • Here's a link to the GitHub page where I asked this too. https://github.com/TaoK/PoorMansTSqlFormatter/issues/285 – Frantumn Mar 08 '23 at 18:30
12

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

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
Nisarg Patil
  • 1,509
  • 1
  • 16
  • 27
8

There is another external SQL for DBeaver. It can be found here: SQLinForm SQL Formatter and can be included as external Formatter like this External Formatter for DBeaver

Guido
  • 926
  • 2
  • 10
  • 19
2

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.

jwpfox
  • 5,124
  • 11
  • 45
  • 42
0

Write click on the screen, this menu will be pop-up, and follow the instructions shown in the attached image. enter image description here

Ali Uppal
  • 41
  • 2
-3

use backtick ` instead of quote " or '

ParagDineshGupta
  • 210
  • 2
  • 10
  • 6
    What question are you answering? – Toto Feb 25 '19 at 13:37
  • in my sublime, if i have a long query statement and i want to break it, i use backtick. for example: var sql="select table1_id, table1_name from table1 where table1_id=? and table1_status=1" ; it will take one line only but using backtic ` i can break it into multiple lines for convenience purpose. – ParagDineshGupta Feb 26 '19 at 05:56