Ctrl + Enter runs. Select part of the text to run only that part.

Data types cheat sheet

Pick the type that matches the kind of value. MySQL checks every value against its column's type and size. SQLite treats a type as a preference and stores what you give it, unless you add STRICT after the closing parenthesis of CREATE TABLE.

Kind of valueMySQLSQLiteExample valueUse it for
Whole numberINTINTEGER42, -7Counts, quantities, ages, years
Very large whole numberBIGINTINTEGER9000000000Numbers past about 2 billion, like phone numbers stored as numbers (better as text)
Small whole numberTINYINT, SMALLINTINTEGER3Ratings, star counts, small codes
Exact decimalDECIMAL(8,2)REAL (or whole cents as INTEGER)19.99Money and gpas. DECIMAL(8,2) means 8 digits in all, 2 after the point
Approximate decimalFLOAT, DOUBLEREAL98.6Measurements where tiny rounding is fine
Short textVARCHAR(40)TEXT'Ana Lopez'Names, emails, titles. The number is the most characters allowed (MySQL only enforces it)
Fixed length textCHAR(2)TEXT'CA'Codes that are always the same length, like states
Long textTEXTTEXTa paragraphDescriptions, notes, comments
DateDATETEXT'2026-10-05'Birthdays, due dates. Always YEAR-MONTH-DAY so dates sort correctly
Date and timeDATETIME, TIMESTAMPTEXT'2026-10-05 14:30:00'When something happened
Time of dayTIMETEXT'14:30:00'Class start times
True or falseBOOLEAN (stored as TINYINT(1))INTEGER1 or 0Yes or no columns like is_active
One of a fixed listENUM('present','absent')TEXT CHECK (status IN ('present','absent'))'present'Statuses and categories with a short, fixed set of choices
Numbered idINT AUTO_INCREMENT PRIMARY KEYINTEGER PRIMARY KEYfilled in for youSurrogate primary keys
NothingNULLNULLNULLA missing or unknown value. Not the same as 0 or an empty string. Test it with IS NULL, never = NULL

Text and dates go inside single quotes. Numbers and NULL do not. Store phone numbers and zip codes as text: they are labels, not amounts, and a leading zero would be lost as a number. More on types in MySQL vs SQLite.

Foreign keys: making one table reference another

A foreign key is a column whose value must match the primary key of a row in another table, such as a player's team_id pointing at a row in teams. You add it with REFERENCES in CREATE TABLE. The table being referenced is the parent, and it must be created, and filled, first.

Way 1: on the column
CREATE TABLE teams (
    team_id INTEGER PRIMARY KEY,
    name    TEXT NOT NULL
);

CREATE TABLE players (
    player_id INTEGER PRIMARY KEY,
    name      TEXT NOT NULL,
    team_id   INTEGER NOT NULL REFERENCES teams(team_id)
);
Way 2: as a line at the end (same as MySQL)
CREATE TABLE players (
    player_id INTEGER PRIMARY KEY,
    name      TEXT NOT NULL,
    team_id   INTEGER NOT NULL,
    FOREIGN KEY (team_id) REFERENCES teams(team_id)
);

Use this form when the key has two columns, or to keep all the keys together at the bottom like the labs do.

  • Turning checks on. SQLite only enforces foreign keys after PRAGMA foreign_keys = ON;, and the setting lasts only for that connection. The playground turns it on for you. In DB Browser for SQLite, the sqlite3 command line, or Python's sqlite3 module, run it yourself every time you connect, or bad rows go in without an error.
  • What a broken reference looks like. Inserting a player with a team_id that no team has, or deleting a team that still has players, fails with FOREIGN KEY constraint failed.
  • Deleting parents. Add ON DELETE CASCADE after the REFERENCES part to delete a team's players along with it, or ON DELETE SET NULL to keep them with no team (the column must then allow NULL).
  • Adding one later. SQLite has no ALTER TABLE ... ADD FOREIGN KEY or ADD CONSTRAINT. Put the reference in CREATE TABLE. To add one to an existing table, create a new table with it, copy the rows over, drop the old table, and rename the new one.
  • Checking your work. In the Tables panel, a column marked FK is a foreign key. PRAGMA foreign_key_list(players); lists a table's references.

How it works

  • The database lives only in this browser tab. Refresh, Reset, or switching databases starts over from the starting data, so you can DROP, DELETE, and UPDATE anything.
  • Your typing is never replaced. Clicking a table name shows its rows without changing the editor, and examples, the Try it buttons, and other databases open in a new editor tab.
  • Each statement's result shows separately. If one fails, the ones before it still ran, and the ones after it did not.
  • A query that runs longer than 5 seconds is stopped and the data is reset, so a loop that never ends can't freeze your browser.
  • Copy link makes a link that opens this page with your query and database already loaded. Handy for asking a question about a query.

Coming from MySQL

This is SQLite, not MySQL, but most lab SQL runs unchanged. The playground also translates a few MySQL habits and tells you when it does:

MySQLHere
SHOW TABLES; and DESCRIBE students;Work
INT AUTO_INCREMENT PRIMARY KEYBecomes INTEGER PRIMARY KEY
CURDATE(), NOW(), CONCAT()Work
IF(a, b, c)Write CASE WHEN a THEN b ELSE c END
Stored procedures, cursors, DECLARE, CALLNot available. Practice those in MySQL
FOREIGN KEY ... REFERENCESWork and are checked. See Foreign keys
TriggersWork, but they can't change NEW. See the Lab 5 trigger examples
Every difference between MySQL and SQLite, side by side