SQL Formatter
Format and beautify SQL queries with support for multiple dialects (PostgreSQL, MySQL, SQL Server, SQLite). Configure keyword case, indentation, and minify options.
How to Use SQL Formatter
What is SQL Formatting?
SQL formatting transforms unreadable, compressed SQL queries into clean, indented, properly spaced code that's easy to read, debug, and maintain. It applies consistent styling rules for keywords, line breaks, and indentation.
Why Format SQL?
- Readability: Make complex queries easier to understand
- Debugging: Spot syntax errors and logic issues faster
- Code Reviews: Consistent formatting helps reviewers focus on logic
- Maintenance: Formatted queries are easier to modify and extend
- Team Standards: Enforce consistent SQL style across your codebase
How to Use This Tool
Format a SQL Query
- Paste your SQL in the input textarea (compressed or messy queries welcome)
- Choose dialect: Select your database (PostgreSQL, MySQL, SQL Server, SQLite, etc.)
- Set keyword case: Choose UPPERCASE, lowercase, or preserve original
- Set indentation: Pick 2 spaces or 4 spaces per indent level
- Click Format to beautify your query
- Copy the formatted SQL with one click
- Use Minify to compress formatted SQL back to a single line
- Try Sample query to see formatting in action
Formatting Options Explained
Dialect
Different SQL databases have slightly different syntax:
- PostgreSQL: Supports RETURNING, advanced CTEs, ARRAY types
- MySQL: Uses backticks for identifiers, different string functions
- SQL Server: Uses square brackets, TOP instead of LIMIT
- SQLite: Lightweight, fewer advanced features
- Standard SQL: Generic SQL that works across most databases
Choose your database dialect for best results.
Keyword Case
- UPPERCASE: SQL keywords in ALL CAPS (traditional style, most readable)
- lowercase: Keywords in lowercase (modern style, less "shouty")
- Preserve: Keep original casing from your input
Indentation
- 2 spaces: Compact, saves horizontal space (common in web dev)
- 4 spaces: More spacious, easier to see nesting levels (common in enterprise)
Formatting Examples
Before Formatting
select u.id,u.name,o.total from users u join orders o on o.user_id=u.id where o.created_at>='2024-01-01' and o.status in ('paid','shipped') order by o.created_at desc limit 50;
After Formatting (UPPERCASE, 2 spaces)
SELECT
u.id,
u.name,
o.total
FROM users u
INNER JOIN orders o ON o.user_id = u.id
WHERE o.created_at >= '2024-01-01'
AND o.status IN ('paid', 'shipped')
ORDER BY o.created_at DESC
LIMIT 50;
Common Use Cases
- Legacy Code: Format old, unformatted queries from legacy systems
- Minified Queries: Expand compressed queries from logs or ORMs
- Code Reviews: Format SQL before committing to version control
- Documentation: Create readable examples for technical docs
- Learning: Study well-formatted queries to understand SQL structure
- Debugging: Format queries to spot missing JOINs, WHERE clauses, or parentheses
- Performance Analysis: Formatted queries make EXPLAIN plans easier to interpret
Minify vs. Format
- Format: Adds line breaks, indentation, spacing for readability
- Minify: Removes all unnecessary whitespace to compress query into one line (useful for embedding in code, reducing file size, or copying to logs)
Tips
- Always format before code review: Makes reviewing easier for teammates
- Use consistent casing: Pick UPPERCASE or lowercase and stick with it across your project
- Format complex subqueries: Nested SELECTs benefit most from formatting
- Preserve original when unsure: Use "preserve" case if working with legacy systems with mixed casing
- Minify for production: Some systems prefer compressed queries for performance
- Test after formatting: Formatting shouldn't change logic, but always test to be safe
Frequently Asked Questions
Most Viewed Tools
Screen Size Converter
Calculate screen width and height from diagonal size and aspect ratio. Convert between inches and centimeters for displays, TVs, and monitors with instant dimension calculations.
Use Tool βDPI Calculator
Calculate DPI (dots per inch), image dimensions, and print sizes. Convert between pixels and physical dimensions for printing and displays.
Use Tool βPaper Size Converter
Convert between international paper sizes (A4, Letter, Legal) with dimensions in mm, cm, and inches. Compare ISO A/B series and North American paper standards.
Use Tool βFuel Consumption Converter
Convert between MPG (miles per gallon), L/100km (liters per 100 kilometers), and other fuel efficiency units. Compare car fuel economy across different measurement systems.
Use Tool βCSV Splitter
Split large CSV files into smaller files by number of rows. Process large datasets in manageable chunks instantly.
Use Tool βProduct Schema Generator
Generate JSON-LD Product schema markup for SEO. Add product details like name, price, brand, rating, and availability to create structured data for rich search results.
Use Tool βLarge Text File Viewer
View and search large text files up to 200MB in your browser. Features virtual scrolling, line numbers, search functionality, and file statistics. Perfect for log files, CSV, JSON, and code files.
Use Tool βAPI Key Generator
Generate secure, cryptographically random API keys for authentication and authorization. Create custom API keys with various formats including hex, base64, and prefixed keys.
Use Tool βRelated Development Tools
JSON Formatter & Validator
FeaturedFormat, validate, and pretty-print JSON with our developer-friendly editor.
Use Tool βQR Code Generator
FeaturedCreate custom QR codes for URLs, text, and contact info
Use Tool βHTML Validator
Validate HTML markup and check for common issues. Detect missing attributes, accessibility problems, deprecated tags, and structure errors. Free and runs entirely in your browser.
Use Tool βCSV Data Type Converter
Convert data types in CSV - Transform CSV column values to numbers, booleans, dates with automatic type detection and cleaning
Use Tool βCSV to Excel Converter
Convert CSV to Excel - Transform comma-separated values to Excel spreadsheet with auto-width columns
Use Tool βTSV to CSV Converter
Convert TSV to CSV - Transform tab-separated values to comma-separated values with automatic quoting
Use Tool βSlug Generator
Generate URL-friendly slugs from any text. Create SEO-optimized slugs for blog posts, products, and web pages instantly.
Use Tool βCSV Splitter
Split large CSV files into smaller files by number of rows. Process large datasets in manageable chunks instantly.
Use Tool βShare Your Feedback
Help us improve this tool by sharing your experience