Write and run SQL right here, on the same tables as the labs. It runs SQLite inside your browser, so nothing is saved and nothing can break. Reset brings back the starting data.
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 value | MySQL | SQLite | Example value | Use it for |
|---|---|---|---|---|
| Whole number | INT | INTEGER | 42, -7 | Counts, quantities, ages, years |
| Very large whole number | BIGINT | INTEGER | 9000000000 | Numbers past about 2 billion, like phone numbers stored as numbers (better as text) |
| Small whole number | TINYINT, SMALLINT | INTEGER | 3 | Ratings, star counts, small codes |
| Exact decimal | DECIMAL(8,2) | REAL (or whole cents as INTEGER) | 19.99 | Money and gpas. DECIMAL(8,2) means 8 digits in all, 2 after the point |
| Approximate decimal | FLOAT, DOUBLE | REAL | 98.6 | Measurements where tiny rounding is fine |
| Short text | VARCHAR(40) | TEXT | 'Ana Lopez' | Names, emails, titles. The number is the most characters allowed (MySQL only enforces it) |
| Fixed length text | CHAR(2) | TEXT | 'CA' | Codes that are always the same length, like states |
| Long text | TEXT | TEXT | a paragraph | Descriptions, notes, comments |
| Date | DATE | TEXT | '2026-10-05' | Birthdays, due dates. Always YEAR-MONTH-DAY so dates sort correctly |
| Date and time | DATETIME, TIMESTAMP | TEXT | '2026-10-05 14:30:00' | When something happened |
| Time of day | TIME | TEXT | '14:30:00' | Class start times |
| True or false | BOOLEAN (stored as TINYINT(1)) | INTEGER | 1 or 0 | Yes or no columns like is_active |
| One of a fixed list | ENUM('present','absent') | TEXT CHECK (status IN ('present','absent')) | 'present' | Statuses and categories with a short, fixed set of choices |
| Numbered id | INT AUTO_INCREMENT PRIMARY KEY | INTEGER PRIMARY KEY | filled in for you | Surrogate primary keys |
| Nothing | NULL | NULL | NULL | A 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.
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.
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)
);
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.
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.team_id that no team has, or deleting a team that still has players, fails with FOREIGN KEY constraint failed.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).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.PRAGMA foreign_key_list(players); lists a table's references.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:
| MySQL | Here |
|---|---|
SHOW TABLES; and DESCRIBE students; | Work |
INT AUTO_INCREMENT PRIMARY KEY | Becomes INTEGER PRIMARY KEY |
CURDATE(), NOW(), CONCAT() | Work |
IF(a, b, c) | Write CASE WHEN a THEN b ELSE c END |
Stored procedures, cursors, DECLARE, CALL | Not available. Practice those in MySQL |
FOREIGN KEY ... REFERENCES | Work and are checked. See Foreign keys |
| Triggers | Work, but they can't change NEW. See the Lab 5 trigger examples |