SQL Formatter & Prettifier
Format, prettify, and minify SQL online. Supports MySQL, PostgreSQL, and SQLite with keyword casing, line numbers, N+1 query detection, and Eloquent-to-SQL explainer.
How to use the SQL Formatter
Paste your SQL query in the input field and it is formatted instantly. Choose a database dialect (MySQL, MariaDB, PostgreSQL, or SQLite), select keyword casing (UPPER, lower, or preserve as-is), and adjust the indent size. Toggle Minify to compact the SQL to a single line. Load an example query to see the formatter in action.
N+1 query detection
If you paste multiple SQL statements that match the same pattern (only the bound value differs), the tool warns you about a likely N+1 problem. The N+1 query problem is a common Eloquent pitfall - for example, loading a list of users and then running a separate query per user to load their posts. The fix is eager loading: User::with('posts')->get() instead of accessing $user->posts inside a loop.
SQL in Laravel
Laravel's query builder and Eloquent let you write expressive queries in PHP without raw SQL. When you do need raw SQL, use parameter bindings to prevent injection: DB::select('SELECT * FROM users WHERE id = ?', [$id]). For debugging, enable the query log with DB::enableQueryLog() and inspect it with DB::getQueryLog(), or use Laravel Telescope's query panel in development.