SQL Formatter & Beautifier Format Any SQL Query Free
Format and beautify SQL queries instantly. Custom indent size (2 spaces, 4 spaces or tabs). UPPERCASE or lowercase keyword casing. MySQL, PostgreSQL, SQLite and MSSQL dialect support. Minify mode for compact output. Comments preserved. 100% browser-side — your SQL never leaves your device.
Format, Beautify or Minify Any SQL Query
Paste your SQL below. Choose your dialect, keyword casing and indent size. Click Format. Runs entirely in your browser — no SQL is sent to any server.
Copied!
SQL dialect support at a glance
Rate this tool
What This SQL Formatter Does — and Why Each Feature Matters
-- comment) and block comments (/* comment */) are preserved in their relative position during formatting. Comments are not removed, relocated or reformatted. This is important for SQL that uses comments as section markers, disable blocks or documentation.Format SQL in 3 Steps
LazyTools vs Other Free SQL Formatters
| Feature | LazyTools | sqlinform.com | freeformatter.com | sqlformat.org |
|---|---|---|---|---|
| MySQL dialect (backtick ids) | ✅ Yes | ✅ Yes | ⚠ Partial | ⚠ Partial |
| PostgreSQL :: type casting | ✅ Yes | ⚠ Partial | ❌ No | ⚠ Partial |
| MSSQL [bracket] identifiers | ✅ Yes | ✅ Yes | ⚠ Partial | ⚠ Partial |
| UPPERCASE / lowercase toggle | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
| Custom indent (2/4/tab) | ✅ Yes | ⚠ Limited | ✅ Yes | ⚠ Limited |
| Minify mode | ✅ Yes | ❌ No | ⚠ Partial | ✅ Yes |
| Comment preservation | ✅ Yes | ✅ Yes | ⚠ Partial | ✅ Yes |
| 100% browser-side (no upload) | ✅ Yes | ❌ Server | ❌ Server | ❌ Server |
| Free, no account | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
SQL Dialect Identifier Syntax Reference
| Dialect | Table identifier | Column identifier | String literal | Unique syntax |
|---|---|---|---|---|
| MySQL | `users` | `user_id` | 'text' or "text" | LIMIT n, GROUP_CONCAT, backticks |
| PostgreSQL | "users" | "user_id" | 'text' | ::integer, RETURNING, ILIKE, WITH |
| SQLite | "users" or `users` | "user_id" | 'text' | PRAGMA, type affinity, no stored procs |
| MSSQL | [users] | [user_id] | 'text' | TOP n, NOLOCK, GO, DECLARE, T-SQL |
SQL Formatter — Why Formatting SQL Matters and How to Do It Right
Why format SQL queries?
Unformatted SQL is one of the most common sources of bugs and maintenance friction in database-driven applications. A query that was written in a single line during rapid development becomes impossible to review in a pull request, impossible to debug when it returns unexpected results, and difficult to optimise when a DBA needs to add indexes. Consistently formatted SQL is easier to read, easier to review, easier to diff and faster to debug. Most style guides for SQL (Google SQL Style Guide, Mozilla SQL Style, etc.) mandate UPPERCASE keywords, one clause per line and consistent indentation — all of which this formatter applies automatically.
MySQL formatting: backtick identifiers
MySQL uses backticks (`table_name`) to quote identifiers, which is its most distinctive dialect feature. This allows table and column names that conflict with MySQL reserved words (for example, `order`, `select`, `key`). A formatter that does not recognise backticks will misparse MySQL queries containing these identifiers. The LazyTools MySQL dialect correctly tokenises backtick-quoted identifiers and preserves them unchanged while reformatting surrounding whitespace and keywords.
PostgreSQL formatting: :: type casting and CTEs
PostgreSQL has several syntax features absent from other dialects. The most common is :: type casting, which casts a value to a specific type inline: price::numeric, created_at::date. PostgreSQL also uses double-quoted identifiers for case-sensitive column names. Common Table Expressions (WITH clauses) are extensively used in PostgreSQL queries. The formatter handles all of these correctly when the PostgreSQL dialect is selected.
MSSQL / SQL Server: T-SQL and square brackets
Microsoft SQL Server uses square brackets ([table_name], [column_name]) as its identifier quoting syntax. T-SQL also includes non-standard extensions like TOP n instead of LIMIT n, NOLOCK query hints, and procedural extensions like DECLARE, SET NOCOUNT ON and GO. Selecting the MSSQL dialect ensures these are recognised and preserved correctly during formatting.
When to use SQL minification
Minified SQL removes all whitespace and newlines to produce a compact single-line version. Use cases include: embedding SQL strings directly in application source code (removes the need for multi-line string concatenation), storing SQL in JSON configuration files where newlines cause parse errors, sending SQL via API payloads where unnecessary bytes add latency, and generating SQL dynamically in environments where whitespace handling is inconsistent. Note that minified SQL is significantly harder to read and debug — keep a formatted version for development and use the minified version in production builds only.
Frequently Asked Questions
MySQL/MariaDB (backtick identifiers, MySQL functions, LIMIT syntax), PostgreSQL (double-quote identifiers, :: type casting, RETURNING, ILIKE, CTEs), SQLite (PRAGMA statements, type affinity), and MSSQL/SQL Server (square bracket identifiers, TOP clause, T-SQL syntax including GO, DECLARE, NOLOCK).
Yes. Both single-line comments (--) and block comments (/* */) are preserved in their relative position during formatting. Comments are never removed or relocated. In Minify mode, comments are stripped as all whitespace is removed to produce a single line.
No. All SQL formatting runs entirely in your browser using JavaScript. No SQL query is sent to any server or third party. This is safe for formatting queries that contain sensitive table names, column names, schema structures or data values that should not leave your environment.
Yes. Select the PostgreSQL dialect. The formatter correctly recognises :: type casting operators (e.g. value::integer, created_at::date) and does not misparse them as two colons or break the formatting around them.
Format mode adds indentation, newlines and consistent spacing to make SQL human-readable. Minify mode removes all whitespace and newlines to produce the most compact single-line version possible. Use Format for development and code review. Use Minify for embedding SQL in application strings, JSON configs or API payloads.
2 spaces is compact and common in web development teams. 4 spaces is the enterprise and DBA standard, matching the indent size used in most SQL style guides (Google, Mozilla). Tabs are preferred by some teams for accessibility reasons (tab width can be configured per-user in editors). Match the existing convention in your codebase.
Yes — this tool formats SQL online free for MySQL and PostgreSQL (and SQLite and MSSQL). Paste your query, select your dialect, choose UPPERCASE or lowercase keywords and your indent size, then click Format SQL. Results copy with one click. No account, no server upload, completely free.
Yes — select 2 spaces, 4 spaces or tab indentation before formatting. The tool applies your chosen indent consistently to all nested clauses (subqueries, CTEs, CASE expressions, JOIN conditions). The formatted output maintains indentation that reflects the logical structure of the query.