SQL Formatter

Format SQL text for better readability.


Before

After

Tips

  • SQL keywords such as SELECT, FROM, WHERE, and JOIN are automatically line-broken and aligned, and nested subqueries are properly indented.
  • Enabling "Capitalize keywords" auto-uppercases all keywords, improving readability.
  • Adjust the indent size to match your team's coding style guidelines.
  • Pasting the formatted SQL into code reviews or documentation makes it much easier to read.
  • Supports major SQL dialects including MySQL, PostgreSQL, and Oracle.

FAQ

Major SQL dialects including MySQL, PostgreSQL, Oracle, and SQL Server are supported. Dialect-specific syntax is interpreted and formatted to the extent possible.

If the input SQL contains syntax errors, the formatter may not parse it correctly. Check that your SQL is valid using a database client before formatting.

You can paste multiple SQL statements separated by semicolons and they will be formatted together. However, stored procedures and PL/SQL block syntax may not be fully supported.
ツールくん

Side Note — 50 Years of SQL: A History of Relational Databases

SQL originated when IBM developed "SEQUEL" based on the relational model proposed by E.F. Codd (IBM) in a 1970 paper (later renamed SQL for trademark reasons). It was standardized by ANSI in 1986 and has been used in countless databases ever since.

One of the most famous security incidents is the SQL injection attack. The 2011 Sony PSN (PlayStation Network) breach exposed over 100 million personal records, with estimated damages of $171 million. It remains a staple on the OWASP Top 10 list, and using prepared statements is considered the fundamental countermeasure.

"WHERE 1=1" is a handy technique for building dynamic SQL, but it's also a classic SQL injection example. The ability to log in without a password by entering ' OR '1'='1 into a login form is still used as a canonical example in security training.