SQL Formatter
Beautify messy SQL queries for MySQL, PostgreSQL, SQL Server, SQLite, BigQuery and more, with keyword case and indent options.
0 characters · 1 line
How to use
- Paste a query into “Input SQL”, or click “Example” to try it out.
- Choose your database dialect (such as MySQL, PostgreSQL or SQL Server); the result is formatted as you type.
- Adjust keyword case, indent, alignment and the position of AND/OR to taste. Your settings are remembered in this browser.
- Click “Copy” or “Download” to grab the formatted SQL. If the syntax is invalid, the error position is marked below the input.
FAQ
Is my SQL uploaded?
No. Formatting happens in your browser; your SQL is never sent to a server and nothing connects to your database.
Why choose a dialect?
Databases differ in syntax: MySQL quotes names with backticks, SQL Server uses [brackets] and PostgreSQL has :: casts. With the right dialect, the formatter recognizes that syntax and its reserved words; database-specific syntax may cause errors with “Standard SQL”.
What does “Keyword case” change?
Keywords such as SELECT and FROM, function names such as COUNT() and data types such as INT and VARCHAR. Table and column names, strings and comments are left as they are.
Can formatting change what my query does?
No. Only whitespace, line breaks, indentation and keyword case change; nothing is added, removed or reordered. Strings and quoted names (including non-English names) are kept exactly.
What should I do about “… is not expected here”?
The formatter could not read the syntax at the marked position. Common causes are unmatched parentheses, a missing closing quote or syntax the chosen dialect does not support. Make sure the right dialect is selected, then check the syntax near the mark.
Can commas go at the start of lines?
The formatting library used here (sql-formatter) no longer supports leading commas, so commas always end the line. The “Tabular” alignments can make long column lists easier to read.
Why does the first use take a moment?
The formatter and each dialect’s keyword lists are fairly large, so they load after the page opens, and only for the dialect you choose. Once loaded, formatting is instant.
Related tools
JSON Formatter
Beautify, minify and validate JSON with precise line and column error locations.String Escape
Escape and unescape text for JSON, JavaScript, HTML, XML, CSV, SQL, shell and regex string literals, with error positions.Text Diff
Compare two texts side by side or inline, with changed words highlighted, ignore whitespace or case, and copy a unified patch.