About the SQL compiler
How to use the SQL compiler
Put your tables and their rows in the Schema & data tab, and your queries in the editor. When you press Run, the schema and data run first on a fresh, empty database, then each statement in the editor runs in order. Every statement that returns rows appears as its own table; INSERT, UPDATE and DELETE say how many rows they changed.
Templates cover CREATE TABLE and INSERT, WHERE, ORDER BY with LIMIT, aggregate functions, GROUP BY with HAVING, INNER and LEFT JOIN, a subquery, UPDATE and DELETE, and a VIEW, on a small table of students and departments.
This is SQLite
The compiler runs SQLite 3.39, the database built into Python. Most course SQL works as written, but some MySQL, Oracle and SQL Server syntax is different. An id that counts up by itself is INTEGER PRIMARY KEY (or INTEGER PRIMARY KEY AUTOINCREMENT), not AUTO_INCREMENT. Join text with || instead of CONCAT(). The current date and time is datetime('now'), not NOW(). There is no TOP: use LIMIT. Columns are loosely typed, so a text value can go into an INTEGER column unless the column is a primary key.
Foreign keys are enforced. Each run starts from an empty database, so the Schema & data tab is how you give your queries something to work on.
Limits and tests
A run may take 5 seconds. A result shows its first 1,000 rows and says how many there were. The database lives in memory in your browser and cannot open files or reach the network.
In the Tests tab, each test gives its own schema and data and the result the last query should return, written one row per line with cells separated by |, starting with the column names. Turn off Order matters when the query has no ORDER BY.
See it step by step
Visualize this run opens the same statements, with the schema and data, in the SQL visualizer: one statement at a time, with every table shown after it runs and the rows each query picked.
Questions
- Which database is this?
- SQLite 3.39, running in your browser. It is not MySQL, so a few things (AUTO_INCREMENT, CONCAT, NOW()) are written differently.
- Where do I create my tables?
- In the Schema & data tab, which runs first on every run, or at the top of the editor.
- Why is my table empty on the next run?
- Each run starts from a fresh database. Put the CREATE TABLE and INSERT statements in the Schema & data tab so they run every time.
- Can I compare a query's result in a test?
- Yes. A test checks the last result table against the rows you expect, in order or in any order.
See also
- The SQL code visualizer: run code one step at a time and see its memory.
- Database Management Systems: the course, with lessons and examples you can open here.
- Practice problems, checked against hidden tests.
- Online Python compiler
- Online C compiler
- Online C++ compiler
- Online Java compiler
- Online JavaScript compiler
- Online 8086 Assembly compiler