SQL Formatter
Format and indent SQL queries. Supports MySQL, PostgreSQL, SQLite, and generic SQL.
Format SQL online: instant pretty printer with dialect support
AlteredIdea's SQL Formatter takes long, single-line SQL queries and transforms them into well-structured, readable code. Each clause: SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY: starts on its own line with consistent indentation and keyword casing applied throughout.
The formatter supports four dialects: Generic SQL, MySQL, PostgreSQL, and SQLite. Selecting the right dialect enables recognition of database-specific keywords so they are formatted correctly rather than treated as identifiers. All processing happens in your browser, so sensitive query logic, table structures, and data patterns stay private.
This is the fastest way to make an API-generated query or an ORM debug output readable for code review, documentation, or debugging. No install, no configuration, no account: just paste and format.
How to format SQL online: step by step
- 1Paste your SQL query
Copy any SQL: a SELECT, INSERT, UPDATE, or DDL statement: and paste it into the Input panel. - 2Choose keyword casing
Select UPPER (SELECT), lower (select), or Title (Select) to match your team's SQL style guide. - 3Set indent size
Choose 2 or 4 spaces for indentation of sub-clauses and column lists. - 4Pick a dialect
Select Generic, MySQL, PostgreSQL, or SQLite to enable dialect-specific keyword recognition like RETURNING or ENGINE. - 5Copy the formatted output
Click Copy to send the formatted SQL to your clipboard, ready to paste into your IDE, migration file, or documentation.
Related Tools
JSON Formatter
Validate, format, minify, and explore JSON. Syntax highlighting, error detection, and tree view.
HTML Beautifier
Format messy HTML with proper indentation. Also minifies HTML for production.
CSS Formatter
Prettify or minify CSS. Auto-prefix properties, sort alphabetically.
Regex Tester
Test regular expressions with live matching, group capture, flags, and match highlighting.
Frequently Asked Questions
- Is my SQL sent to a server?
- No. All formatting runs entirely in your browser using JavaScript string processing. Your SQL queries: including any table names, column names, or data values: never leave your device.
- What SQL dialects are supported?
- The formatter supports Generic SQL, MySQL, PostgreSQL, and SQLite. Dialect selection enables recognition of dialect-specific keywords like RETURNING (PostgreSQL) or ENGINE (MySQL).
- Will the formatter work on very long queries?
- Yes. The formatter handles arbitrarily long single-line queries and multi-statement scripts. Very complex queries with many subqueries may take a moment but there is no hard size limit.
- Does it support CTEs and subqueries?
- Yes. WITH clauses and subqueries are recognized and formatted. Complex nested queries may have partial formatting where the nested SELECT is treated as a text block.
- What is keyword casing?
- SQL keywords like SELECT, FROM, WHERE can be written in uppercase, lowercase, or title case. The formatter converts all recognized keywords to your chosen style while leaving identifiers and string literals unchanged.
- Does it format DDL statements like CREATE TABLE?
- Yes. CREATE TABLE, ALTER TABLE, DROP TABLE, and similar DDL statements are recognized and placed on their own lines with proper structure.
- Can I format multiple SQL statements at once?
- Statements separated by semicolons are handled as part of the same input. Each major statement keyword triggers a new section in the output.
- Why are some identifiers still in their original case?
- Only SQL keywords are reformatted. Table names, column names, aliases, and string literals are left exactly as you entered them.
- Does it remove SQL comments?
- No. The formatter preserves SQL comments (-- single line and /* block */) in the output.
AlteredIdea vs alternatives
vs online SQL formatters: Most online SQL formatters send your queries to their server. AlteredIdea formats entirely client-side: production queries and sensitive table schemas stay private.
vs IDE plugins: IDE SQL formatters require an active database connection or a specific plugin per editor. AlteredIdea works in any browser without installing anything.
vs paid tools: Completely free with no account and no usage limits. Format as many queries as you need across all supported dialects.