Loading tool...
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
Format messy SQL queries into clean, readable code with proper indentation and keyword casing for easier review and understanding. SQL code from different sources—auto-generated queries, logs, and legacy code—often lacks consistent formatting, making it hard to read and review. This tool reformats SQL automatically with proper indentation, keyword casing, and line breaks that follow SQL conventions. Customize indentation (spaces or tabs), keyword casing (UPPERCASE, lowercase, or mixed), and optionally minify for compact representation. Support for multiple SQL dialects ensures output matches your database system. Perfect for code review preparation, documentation, debugging, and making complex queries understandable.
Format SQL queries before review to ensure consistent style and improve reviewability of complex queries.
Format hard-to-read SQL from logs or auto-generated sources to make them understandable and maintainable.
Format example SQL queries for documentation and tutorials to establish consistent styling conventions.
Format complex queries to better understand their structure, identifying optimization opportunities.
Format queries from error logs to understand their structure and identify syntax issues.
Study well-formatted SQL queries to learn SQL conventions and best practices.
SQL (Structured Query Language) has one of the longest and most influential histories of any programming language still in active use. Its origins trace to a 1970 paper by Edgar F. Codd at IBM, "A Relational Model of Data for Large Shared Data Banks," which proposed organizing data into mathematical relations (tables) and manipulating them through relational algebra operations. Donald Chamberlin and Raymond Boyce at IBM's San Jose Research Laboratory developed SEQUEL (Structured English Query Language) in 1974 as a practical implementation of Codd's relational algebra, designed to be readable by non-programmers. The name was later shortened to SQL due to a trademark conflict.
The theoretical foundation of SQL is relational algebra, a formal system defining operations on relations (tables): selection (filtering rows), projection (selecting columns), join (combining tables), union, intersection, difference, and the Cartesian product. Every SQL query can be decomposed into these fundamental operations, and query optimizers inside database engines translate SQL's declarative syntax into execution plans based on relational algebra equivalences. For example, the optimizer might push a WHERE filter before a JOIN operation (predicate pushdown) because relational algebra proves the result is identical but the execution is faster with fewer rows to join.
SQL standardization began with SQL-86 (also called SQL-87), the first ANSI/ISO standard, which codified basic SELECT, INSERT, UPDATE, and DELETE operations. SQL-92 (also known as SQL2) was a major expansion that introduced JOIN syntax (INNER JOIN, LEFT JOIN, etc. — before SQL-92, joins were expressed only through WHERE clause conditions), subqueries, CASE expressions, string operations, and temporary tables. This standard defined three conformance levels (Entry, Intermediate, Full), and most databases implemented Entry-level SQL-92 plus vendor-specific extensions.
Subsequent standards added increasingly sophisticated features: SQL:1999 introduced common table expressions (WITH/CTE), recursive queries, triggers, and the controversial user-defined types (moving SQL toward object-relational capabilities). SQL:2003 added window functions (OVER, PARTITION BY, ROW_NUMBER), XML support, and auto-generated columns. SQL:2011 introduced temporal tables for time-versioned data. SQL:2016 added JSON support, row pattern matching, and polymorphic table functions. SQL:2023, the most recent standard, added property graph queries and enhanced JSON path support.
Despite this extensive standardization, SQL dialects vary significantly in practice. MySQL uses backticks for identifier quoting and LIMIT for row limiting; PostgreSQL uses double quotes and also supports LIMIT; SQL Server uses square brackets and TOP; Oracle uses double quotes and ROWNUM (now also FETCH FIRST). Stored procedure syntax, date functions, string concatenation, and auto-increment columns all differ across databases. This dialect fragmentation is why SQL formatting tools must be dialect-aware — formatting a PostgreSQL array literal or a SQL Server CTE hint requires understanding the specific syntax extensions beyond standard SQL.
SQL formatting conventions have emerged through decades of community practice rather than formal specification. The most widely accepted convention is uppercase keywords (SELECT, FROM, WHERE, JOIN) with lowercase identifiers, each major clause starting on a new line, and consistent indentation for sub-clauses and conditions. This convention improves readability by creating visual landmarks that help readers quickly identify the structure of complex queries.
No, formatting only changes whitespace, indentation, and keyword casing. The query logic and execution plan remain identical. It is purely a visual transformation for readability.
The formatter works with standard SQL syntax that is compatible with MySQL, PostgreSQL, SQLite, SQL Server, Oracle, and other major databases. Dialect-specific syntax is preserved during formatting.
You can format SQL keywords as UPPERCASE (SELECT, FROM, WHERE), lowercase (select, from, where), or leave them unchanged. Uppercase keywords is the most common convention for readability.
Yes, the minify option removes all unnecessary whitespace and line breaks, producing a compact single-line query. This is useful for embedding SQL in code strings or reducing log file size.
All processing happens directly in your browser. Your files never leave your device and are never uploaded to any server.