Auto Format SQL

<< Click to Display Table of Contents >>

Navigation:  SQL/Code Editor Tools >

Auto Format SQL

Whenever you're in a code or SQL editor, you can use the context menu to auto format your code and SQL statement(s). This will re-arrange the text into a format as specified in the Preferences.

 

View Editor, before formatter has been invoked

 

Here's an example, use the editor context menu or the shortcut and the SQL will be formatted.

 

View Editor, after formatter has been invoked

 

As you can see, the SQL has been formatted: all the items in the SELECT-clause have been lined up, JOINs moved to new lines and so on.

 

An extra bonus with regard to MySQL: this database system doesn't store the actual SQL used for a VIEW. Instead, it returns the SELECT-statement with table names including the database name, at a single line, like in the screen shot below. It makes for a very uncomfortable read.

 

When you format the SELECT-statement, Database Workbench will remove the database name (for the current database) from the statement making it easier to read and easier to execute on a similar, but differently named database.

 

MySQL, view SELECT-statement formatted