SQL formatter

Paste a one-line query to get a version that is easy to read and review. It runs in your browser and never sends the query anywhere.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter sql query, indent and keyword case.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

It splits the query into tokens (strings, comments, names, numbers, operators), puts main clauses on their own lines, columns after commas and AND/OR conditions on indented lines, and indents subqueries one level deeper.

Example

Inputs: Indent = 2 spaces, Keyword case = UPPER. Result: Formatted SQL: SELECT id, name FROM users WHERE active = 1 AND city = 'Riyadh' ORDER BY name; Lines: 10.

select id, name from users where active = 1 and city = 'Riyadh' order by name
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
  AND city = 'Riyadh'
ORDER BY
  name

Limits and caveats

  • Basic formatting for SELECT, INSERT, UPDATE, DELETE and joins; it does not understand every stored procedure syntax.
  • Backslashes inside strings are treated as plain characters, as in standard SQL, so MySQL \' can confuse it.

Questions about this tool

Does formatting change what the query returns?

No. It only changes spacing, line breaks and keyword case, and leaves strings and quoted names untouched.

Can I keep keywords as I typed them?

Yes, pick Keep as typed in the keyword case list.

Does it handle several statements?

Yes. Separate them with semicolons and they come out with a blank line between them.