SQL Formatter
Format and beautify SQL queries with keyword capitalization and indentation
SQL Formatter & Beautifier — Format SQL Queries with Keyword Capitalization, Intelligent Indentation, and Dialect-Specific Syntax for MySQL, PostgreSQL, SQLite, and T-SQL
- Paste your SQL query into the input textarea — the tool accepts everything from single-line SELECT statements to multi-hundred-line stored procedures with CTEs, subqueries, window functions, and complex JOIN hierarchies. SQL (Structured Query Language) is the universal language of databases, but SQL formatting is notoriously inconsistent — queries copied from database logs, ORM-generated SQL, or legacy codebases are often compressed into single lines or indented with chaotic spacing. Poorly formatted SQL is not just aesthetically unpleasant — it's harder to debug, harder to optimize (query structure becomes invisible), and harder to review for security issues (SQL injection points hide in dense, unformatted queries).
- Select your SQL dialect from the dropdown to ensure correct keyword recognition and formatting. Different SQL dialects have different keyword sets and syntax variations: Standard SQL (ANSI/ISO) — the baseline that all dialects extend; MySQL — includes MySQL-specific keywords (LIMIT, AUTO_INCREMENT, ENGINE) and backtick identifier quoting; PostgreSQL — supports RETURNING, ILIKE, JSONB operators, and dollar-quoted strings; SQLite — the embedded database dialect with REPLACE and special pragma support; T-SQL (Transact-SQL) — Microsoft SQL Server's dialect with TOP, MERGE, bracket identifier quoting, and stored procedure syntax. Selecting the correct dialect ensures that dialect-specific keywords are properly capitalized and formatted.
- Click Format to beautify your SQL. The formatter applies consistent styling: keyword capitalization — all SQL keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, INSERT INTO, CREATE TABLE) are uppercased for visual prominence; intelligent indentation — each clause starts on a new line, subqueries are indented one level deeper, JOIN conditions align under their ON clauses, CASE expressions indent WHEN/THEN/ELSE branches; column alignment — multi-column SELECT lists align each column on its own line; parenthesis matching — nested function calls and subexpressions maintain proper bracket pairing with readable indentation. The formatter handles complex patterns correctly: CTEs (WITH ... AS), window functions (ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)), multi-table JOINs with nested conditions, UNION/INTERSECT/EXCEPT queries, and deeply nested subqueries. All formatting uses the sql-formatter library running entirely in your browser — your database queries, which may contain table schemas revealing business logic, never leave your device.
Enable JavaScript to use these tools.