toolulu Easy · Ready · Everywhere

Your connection

…

Local time
—
Time zone
—
Reverse DNS
—
System
—
Browser
—
LogligentMonitoring & Security Intelligence Understand what your
servers are telling youAlready been hacked? Yes? No? Don't know?
Logligent detects and responds.
Sign up free

Run it. Get results.

SQL Formatter

Free
Format SQL queries so they are easy to read: clauses on their own lines, keywords in capitals, sub-queries indented. Free, in your browser.
tooluluEasy · Ready · Everywhere

Use your phone as the camera

Scan this code with your phone's camera, then take a photo of the text. Its words appear here, ready to translate.

Waiting for your phone…

The code works for 15 minutes, for up to 10 photos. Photos are read, then thrown away.

Popular

Pick your tool

toolulu Easy · Ready · Everywhere

156 tools

Open this tool?

About the SQL Formatter

A free SQL formatter: paste a query and get it laid out so it is easy to read, with each clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY…) on its own line, the column list and conditions one a line, sub-queries indented and keywords in capitals (or lowercase). Minify it back to one line, copy it or download it as a .sql file. Strings, quoted names and comments are left exactly as they are, and nothing is run or sent.

How to use it

  1. Paste your SQL (MySQL, PostgreSQL, SQL Server, Oracle or SQLite).
  2. Choose capitals or lowercase keywords and the indent: it is formatted as you type.
  3. Copy or download it, or press Minify for one line.

Questions

Which databases does it support?

The SQL they share: MySQL, MariaDB, PostgreSQL, SQL Server, Oracle and SQLite. Special syntax is kept as it is.

Will it change what my query does?

No: only spaces and line breaks change (and keyword case). Strings, names in quotes and comments are untouched.

Does it check my SQL?

It warns about unclosed brackets, quotes and comments; it doesn't run the query, so other mistakes show up only in your database.

Can I format several statements?

Yes: separate them with ; and each is formatted on its own.

Is my SQL sent anywhere?

No: it is formatted in your browser and never run or saved.

Why use capitals for keywords?

It is a common convention that makes SELECT, FROM and WHERE stand out from table and column names. Choose lowercase if your team prefers it.

Did you know?

Tables: 1970

Codd's relational model

E. F. Codd published "A Relational Model of Data for Large Shared Data Banks" in June 1970 in Communications of the ACM.

Source: Oracle

SEQUEL to SQL

SEQUEL became SQL

IBM's Donald Chamberlin and Raymond Boyce wrote "SEQUEL: A structured English query language" in 1974; SEQUEL later became SQL, still pronounced "sequel".

Source: The Register

A database: 1979

The first commercial SQL

In 1979, Relational Software, Inc. (now Oracle) introduced the first commercially available implementation of SQL.

Source: Oracle

Many small databases

A trillion databases

SQLite says it is likely used more than all other database engines combined, with over one trillion SQLite databases in active use.

Source: SQLite

PD

Public domain

All of SQLite's code and documentation has been dedicated to the public domain by its authors.

Source: SQLite

POSTGRES, Berkeley: 1986

Born at Berkeley

PostgreSQL comes from the POSTGRES project at the University of California, Berkeley, led by Michael Stonebraker; its implementation began in 1986.

Source: PostgreSQL

Tips for Readable SQL

  1. Capital keywords

    SELECT, FROM, WHERE in capitals stand out.

  2. One clause a line

    Each clause on its own line is easy to scan.

  3. Clear aliases

    Short, clear aliases: c for customers, o for orders.

  4. Name the columns

    List the columns instead of SELECT *.

  5. UPDATE needs WHERE

    An UPDATE or DELETE without WHERE changes every row.

  6. Use parameters

    Use ? parameters, never text pasted from users: it stops SQL injection.

  7. Comment the tricky parts

    A -- comment explains why.

  8. Minify for code

    Minify a query to put it in a code string.

Advertisements

tooluluEasy · Ready · Everywhere

Advertisements

AcesFive