SQL Formatter

Format SQL queries.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste a one-line SQL query and get it back readable. Each clause starts a new line, selected columns are listed one per line, JOINs line up, AND and OR conditions are indented and subqueries are nested. String literals are left as they are.

How to use

1
Step 1
Paste your SQL into the Input box.
2
Step 2
Press Run.
3
Step 3
Copy the formatted query.

How it works

The query is tokenised so strings and comments are protected, then clause keywords such as SELECT, FROM, WHERE, GROUP BY, ORDER BY and every JOIN start a new line. Commas in SELECT, SET, GROUP BY and ORDER BY lists break lines, AND and OR in WHERE are indented, and a SELECT inside parentheses is indented one level.

Worked example

A filtered query

Input
select id, name from users where active = 1 and age > 18 order by name
Output
SELECT id, name FROM users WHERE active = 1 AND age > 18 ORDER BY name
Walkthrough
Keywords are uppercased and each clause and column gets its own line.

Limitations

  • It is keyword based and does not validate SQL or know any one dialect.
  • Only the main clause keywords are uppercased; function and column names keep their case.
  • CASE expressions and CTEs stay on a single line.

Questions

Does it change my string values?
No. Text inside quotes is copied as written.
Does it work for INSERT and UPDATE?
Yes, INSERT INTO, VALUES, UPDATE, SET and DELETE FROM start new lines too.
Will it fix invalid SQL?
No, it only changes layout.
Is the query uploaded?
No, it is formatted in your browser.

Features

  • Clause per line
  • JOIN and AND/OR indentation
  • Subquery nesting
  • Strings preserved

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Learn JSON - Full Crash Course for Beginners

    freeCodeCamp.org

    Formatted JSON is easier to read once you know the structure.

    Watch on YouTube
  • What Is A RESTful API?

    Traversy Media

    API context for JWT, JSON, and encoding utilities.

    Watch on YouTube
  • JSON.stringify()

    MDN

    Pretty-print spacing options that JSON formatters emulate.

  • MDN Web Docs

    MDN

    Primary reference for web APIs these developer tools touch.