Sign up free

Online SQL Formatter and Beautifier

Paste a query and get each clause and column on its own line, with keywords in the case you choose.

About SQL Formatter

A SQL formatter makes long queries readable: a one-line statement copied from an application log or ORM debug output, a report query someone wrote years ago, or SQL you're about to paste into a code review or a ticket. Paste the query or open a .sql file, and the formatted version appears as you type. If the query runs on a schedule, the Cron Expression Generator builds the timing and lists the next run times.

New lines start before SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, each kind of JOIN, UNION, INSERT, VALUES, UPDATE, SET and DELETE. Selected columns go one per line, AND and OR conditions line up, and subqueries are indented. Keywords can be upper case, lower case or left as typed, and the indent is 2 spaces, 4 spaces or tabs. Text in single quotes, double quotes, backticks and square brackets is never split, and comments are kept, so it copes with MySQL, PostgreSQL, SQL Server, Oracle and SQLite. Tick One line to do the reverse and put the whole query on a single line. It all runs in your browser.

How to use SQL Formatter

  1. 1
    Paste your SQL

    Paste the query or open a .sql file.

  2. 2
    Set keyword case and indent

    Choose SELECT, select or As typed, then 2 spaces, 4 spaces or tabs.

  3. 3
    Copy the result

    Copy or download the formatted SQL, or tick One line to get it on a single line.

Why use Cubfile for this

  • A line per clause

    SELECT, FROM, WHERE, JOIN, GROUP BY and the rest each start a new line.

  • Readable conditions

    AND and OR line up, columns go one per line and subqueries are indented.

  • Every quoting style

    Quoted text in '…', "…", `…` or […] is never split, and comments are kept.

  • One-line option

    Squeeze a query onto a single line for code strings and config files.

FAQ

SQL Formatter: questions and answers

Which databases does the SQL formatter support?
It understands the quoting and comment styles used by MySQL, PostgreSQL, SQL Server, Oracle and SQLite, including backticks and square brackets around names.
Can I make SQL keywords upper case?
Yes. Choose upper case for SELECT, FROM and WHERE, lower case for the opposite, or leave keywords as you typed them.
Can I put a formatted query back on one line?
Yes. Tick One line and the line breaks and indentation go, leaving the statement on a single line for code strings and config files.
How are subqueries formatted?
Each subquery is indented one level deeper than the query around it, with its own clauses on new lines, so nested SELECTs are easy to follow.
Is my SQL uploaded when I format SQL online?
No. Formatting happens in your browser, so table names and data in your queries never reach our server. There's no sign-up and no daily limit. The other code formatters, for HTML, CSS, JavaScript and XML, also run in your browser.
Share SQL Formatter with a friendIt runs in any browser, and they can try it without signing up.

Related tools

HTML HTML FormatterIndent messy HTML so it’s easy to read.
JS JavaScript FormatterBeautify minified or messy JavaScript.
HEX Color ConverterConvert colors between HEX, RGB, HSL and CMYK, and check contrast.
CRON Cron Expression GeneratorBuild cron expressions and see the next run times in plain words.
CSS CSS FormatterTurn minified CSS into neat, readable rules.
CSS CSS MinifierMinify CSS to load faster.
HTML HTML MinifierShrink HTML by removing comments and extra whitespace.
HTTP HTTP Request TesterSend GET, POST and other requests to a public API and read the response.