Format and beautify SQL queries with syntax highlighting. Supports multiple dialects and customizable formatting options.
Paste a SQL query, however tangled, and get a neatly formatted version with proper indentation, keyword capitalization, and line breaks. Supports SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and complex joins across common SQL dialects.
Initializing in your browser…
Format, validate XML with XPath queries, interactive tree view, XML-to-JSON conversion, and multiple color themes
Format, validate, and convert between YAML and JSON formats. Live validation, syntax highlighting, and bidirectional conversion.
Minify or beautify code in 7 languages: JavaScript, TypeScript, CSS, HTML, JSON, XML, SQL with compression visualization
You inherited a 12-line query crammed onto one line and need it readable before you can safely change a JOIN.
Input
select id,name from users u join orders o on o.uid=u.id where o.total>100
Formatted
SELECT id, name FROM users u JOIN orders o ON o.uid = u.id WHERE o.total > 100
Keywords are cased and clauses placed on their own lines with consistent indentation, so the JOIN condition and filter are obvious and a missing predicate would jump out. Formatting is local, which matters because real queries often contain table and column names you should not paste into an external service.
Paste a SQL query, however tangled, and get a neatly formatted version with proper indentation, keyword capitalization, and line breaks. Supports SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and complex joins across common SQL dialects.
The SQL Formatter is a regular-expression beautifier that runs entirely in your browser with no external SQL parsing library. When you click Format SQL, it first collapses all runs of whitespace to single spaces (sql.replace(/\s+/g, ' ')), then walks a fixed list of roughly ninety keywords (SELECT, FROM, WHERE, JOIN, GROUP/BY, HAVING, ORDER/BY, LIMIT, INSERT, INTO, VALUES, UPDATE, SET, DELETE, CREATE, TABLE, WITH, UNION, plus type names like VARCHAR, SERIAL, DECIMAL, TIMESTAMP and functions like COUNT, COALESCE, NULLIF and NOW) and rewrites each whole-word match to your chosen keyword case via a case-insensitive \b regex. It then inserts line breaks before every major clause, pushes each AND, OR, and ON onto its own indented line, and breaks on commas. Because it only recognizes the words in its built-in SQL_KEYWORDS list, identifiers, vendor-specific functions, or newer keywords outside that set are left untouched in whatever case you typed them.
Layout is controlled by three on-screen dropdowns whose values persist in the page URL (via useUrlStates) so a configured formatter can be shared as a link: keyword case (UPPERCASE, lowercase, Capitalize), indent width, and comma position. The indent dropdown offers '2 spaces,' '4 spaces,' and '1 tab,' but indentation is built with the JavaScript expression ' '.repeat(indentSize) where the '1 tab' option maps to indentSize=1, so all three options produce spaces and '1 tab' yields a single space rather than an actual tab character. Comma position can be set to 'After (item,)' (trailing) or 'Before (, item)' (leading). The formatter always normalizes the statement to end with a semicolon, appending one if your input lacks it. Subquery nesting is handled with a light touch: an opening parenthesis immediately followed by SELECT gets a newline and one level of indent, and a doubled closing parenthesis ')\s*)' is split onto separate lines, but there is no true bracket-depth tracking, so deeply nested queries may not indent perfectly.
Although the type SqlDialect (standard, mysql, postgresql, sqlite, mssql) and a default 'standard' value exist in the component's URL state, there is no dialect dropdown rendered in the interface and the dialect value is never read by either the formatting or the minifying logic, so output is identical regardless of dialect; the only visible settings are keyword case, indent, and comma position. Alongside formatting, a Minify button strips the query to a single line by collapsing whitespace and removing the spaces around commas, parentheses, and equals signs (=). The formatted output is shown with regex-based syntax highlighting that colors single-quoted strings green (text-green-400), numeric literals orange (text-orange-400), recognized keywords blue (text-blue-400), and -- line comments gray (text-gray-500), and you can copy it, download it as formatted.sql, or read the live stats panel showing original and formatted character counts, total line count, and the count of recognized keywords. Seven preset sample queries (simple, complex, subquery, cte, insert, update, create) are available as one-click loaders.
Format machine-generated or ORM-produced queries into readable SQL for debugging and review.
Standardize SQL formatting before committing to version control so diffs are meaningful and reviews are easier.
Format complex queries cleanly for inclusion in runbooks, wiki pages, or onboarding documents.
See how a complex query is structured by formatting it with clear indentation, useful for understanding unfamiliar queries.
Paste SELECT id, name FROM users WHERE status = 'active' ORDER BY created_at DESC and click Format SQL to get each clause (SELECT, FROM, WHERE, ORDER BY) on its own line with the column list broken on commas and a trailing semicolon added.
Click Minify to collapse a multi-line query to one line, removing spaces around commas, parentheses, and equals signs, handy when pasting SQL into a string literal in application code.
The formatter handles standard SQL and common dialects including PostgreSQL, MySQL, SQLite, and Microsoft SQL Server syntax.
No. Formatting only affects whitespace and capitalization. The query logic and results remain identical.
Basic procedural SQL (BEGIN/END blocks, IF statements) is supported, though very complex dialect-specific syntax may not format perfectly.
Your text is processed locally in the browser. Nothing you paste or open is transmitted or logged.