The labs use MySQL. The SQL Playground and the Capstone starter use SQLite. Most SQL is the same in both. This page lists the commands that are not.
A program that runs all the time and holds many databases. Many people connect to it at once, each with a user name, password, and permissions. It is what most web applications with many users run on.
A library built into the program using it, with the whole database in one file. No server, no users, no setup. It ships inside Python, every phone, and every web browser, which makes it the most widely used database in the world.
Try the SQLite side in the SQL Playground
The commands that show what is in a database. The SQLite .tables style commands only work in the sqlite3 command line program; the SELECT versions work anywhere, including the playground.
| MySQL | SQLite | Notes |
|---|---|---|
| mysql -u root -p | sqlite3 school.db | Opening a database. SQLite creates the file if it does not exist. |
| SHOW DATABASES; USE school; | (none) | In SQLite, one file is one database. You pick it when you open it. |
| SHOW TABLES; | .tables SELECT name FROM sqlite_master WHERE type = 'table'; | sqlite_master is SQLite's list of every table, view, index, and trigger. The playground also accepts SHOW TABLES. |
| DESCRIBE students; | .schema students PRAGMA table_info(students); | PRAGMA table_info lists each column with its type, NOT NULL, default, and primary key. The playground also accepts DESCRIBE. |
| SHOW CREATE TABLE students; | SELECT sql FROM sqlite_master WHERE name = 'students'; | SQLite stores the exact CREATE TABLE you wrote. |
| SHOW INDEX FROM students; | PRAGMA index_list(students); | |
| SELECT DATABASE(); | PRAGMA database_list; | |
| exit | .quit | Leaving the command line program. |
| MySQL | SQLite | Notes |
|---|---|---|
| student_id INT AUTO_INCREMENT PRIMARY KEY | student_id INTEGER PRIMARY KEY | Both number new rows for you. In SQLite it must be spelled INTEGER, not INT. |
| ) AUTO_INCREMENT = 500; | (no option) | To start at 500 in SQLite, insert the first row with id 500 yourself. The next row gets 501. |
| (ids are never reused) | student_id INTEGER PRIMARY KEY AUTOINCREMENT | Plain INTEGER PRIMARY KEY uses the largest id plus 1, so deleting the newest row lets its id be used again. Add AUTOINCREMENT (no underscore) to prevent that. |
| Foreign keys are checked | PRAGMA foreign_keys = ON; | SQLite ignores foreign keys unless this is turned on for the connection. The playground and the Capstone starter turn it on. |
| ENUM('present', 'absent') | status TEXT CHECK (status IN ('present', 'absent')) | SQLite has no ENUM. A CHECK constraint does the same job, and works in MySQL 8 too. |
| ALTER TABLE students MODIFY gpa DECIMAL(5,2); | (not available) | SQLite cannot change a column's type. Make a new table, copy the rows over, drop the old one, and rename. |
| ALTER TABLE students ADD COLUMN email VARCHAR(80); | ALTER TABLE students ADD COLUMN email TEXT; | The same in both. |
| ALTER TABLE students DROP COLUMN email; | ALTER TABLE students DROP COLUMN email; | The same in both. |
| ALTER TABLE students RENAME COLUMN gpa TO grade_avg; | ALTER TABLE students RENAME COLUMN gpa TO grade_avg; | The same in both. |
MySQL enforces each column's type and size. SQLite is relaxed: a column's type is a preference, and it stores what you give it. VARCHAR(10) happily holds 500 characters, and a word fits in an INTEGER column. Add STRICT after the closing parenthesis of CREATE TABLE to make SQLite check types.
| MySQL | SQLite | Notes |
|---|---|---|
| INT, SMALLINT, BIGINT | INTEGER | |
| VARCHAR(40), CHAR(2), TEXT | TEXT | VARCHAR(40) is accepted, but the 40 is not enforced. |
| DECIMAL(5,2), FLOAT(4,2) | REAL | SQLite has no fixed decimal type. Use ROUND(x, 2) when you show money or gpas. |
| DATE, DATETIME, TIMESTAMP | TEXT holding '2026-10-05' or '2026-10-05 14:30:00' | Always write dates as YYYY-MM-DD so they sort and compare correctly. |
| BOOLEAN, TRUE, FALSE | INTEGER, 1, 0 | SQLite accepts TRUE and FALSE but stores them as 1 and 0. |
| MySQL | SQLite | Notes |
|---|---|---|
| INSERT IGNORE INTO ... | INSERT OR IGNORE INTO ... | Skips a row that would break a key or UNIQUE rule, instead of failing. |
| INSERT ... ON DUPLICATE KEY UPDATE score = 95; | INSERT ... ON CONFLICT (test_score_id) DO UPDATE SET score = 95; | Insert, or update the row that is already there. |
| REPLACE INTO ... | REPLACE INTO ... | The same in both: deletes the old row and inserts the new one. |
| SELECT LAST_INSERT_ID(); | SELECT last_insert_rowid(); | The id of the row you just inserted. |
| TRUNCATE TABLE report_card; | DELETE FROM report_card; | SQLite has no TRUNCATE. Without AUTOINCREMENT, ids start over at 1 once the table is empty, like TRUNCATE in Lab 5i. |
| START TRANSACTION; | BEGIN; | Both accept BEGIN. COMMIT and ROLLBACK are the same. |
| MySQL | SQLite | Notes |
|---|---|---|
| CONCAT(first_name, ' ', last_name) | first_name || ' ' || last_name CONCAT(first_name, ' ', last_name) | SQLite has CONCAT since version 3.44 (2023). Careful: in MySQL, || means OR, not join text. |
| IF(gpa >= 90, 'Honors', 'Other') | iif(gpa >= 90, 'Honors', 'Other') | CASE WHEN gpa >= 90 THEN ... ELSE ... END works in both, so it is the safest choice. |
| IFNULL(gpa, 0) | IFNULL(gpa, 0) | The same in both. COALESCE also works in both. |
| LENGTH(name) | LENGTH(name) | MySQL counts bytes, so an accented letter can count as 2. Use CHAR_LENGTH in MySQL to count characters. SQLite counts characters. |
| GROUP_CONCAT(name SEPARATOR ', ') | GROUP_CONCAT(name, ', ') | Joins a group's values into one piece of text. |
| RAND() | RANDOM() | MySQL gives a decimal from 0 to 1. SQLite gives a large whole number. ORDER BY RAND() and ORDER BY RANDOM() both shuffle rows. |
| SUBSTRING(name, 1, 3) | SUBSTR(name, 1, 3) | SQLite also accepts SUBSTRING. |
| ROUND, UPPER, LOWER, TRIM, REPLACE, ABS, COUNT, SUM, AVG, MIN, MAX | (the same) | These work the same in both. |
SQLite does dates with four functions, date(), time(), datetime(), and strftime(), plus modifiers like '+7 days'. Add 'localtime' to get your own time zone instead of UTC.
| MySQL | SQLite | Notes |
|---|---|---|
| CURDATE() | date('now', 'localtime') | The playground also accepts CURDATE(). |
| NOW() | datetime('now', 'localtime') | The playground also accepts NOW(). |
| YEAR(attended_on) | strftime('%Y', attended_on) | strftime gives text. Wrap it in CAST(... AS INTEGER) to compare it with a number. |
| DATE_FORMAT(attended_on, '%m/%d/%Y') | strftime('%m/%d/%Y', attended_on) | |
| DATE_ADD(attended_on, INTERVAL 7 DAY) | date(attended_on, '+7 days') | Also '-1 month', '+1 year', 'start of month'. |
| DATEDIFF(returned_on, loaned_on) | julianday(returned_on) - julianday(loaned_on) | Days between two dates. |
| MySQL | SQLite | Notes |
|---|---|---|
| WHERE last_name = 'singh' | WHERE last_name = 'singh' | Finds Singh in MySQL but not in SQLite. MySQL compares text ignoring case by default; SQLite's = is exact. In SQLite, write WHERE last_name = 'singh' COLLATE NOCASE. |
| WHERE last_name LIKE 's%' | WHERE last_name LIKE 's%' | LIKE ignores case in both. |
| LIMIT 5 OFFSET 10 | LIMIT 5 OFFSET 10 | The same in both, as is LIMIT 10, 5. |
| (no FULL OUTER JOIN) | FULL OUTER JOIN | SQLite added RIGHT and FULL OUTER JOIN in 3.39 (2022). In MySQL, combine a LEFT JOIN and a RIGHT JOIN with UNION. |
| WITH RECURSIVE, window functions | WITH RECURSIVE, window functions | Both have them (MySQL 8 and later). |
| `table name` | "table name" or `table name` | Quoting a name. Single quotes are for text in both. |
| # a comment -- a comment | -- a comment | MySQL needs a space after the two dashes. # comments are MySQL only. /* ... */ works in both. |
This is the biggest difference. SQLite has no procedural SQL at all, because the program using it (Python, for example) does that work instead. Practice the Chapter 5 procedure and cursor labs in MySQL.
| MySQL | SQLite | Notes |
|---|---|---|
| CREATE PROCEDURE, CALL | (not available) | Write the steps in Python and run one SQL statement at a time. See Stored procedures in plain terms. |
| CREATE FUNCTION | (not available in SQL) | Python can add a function to SQLite with connection.create_function(). |
| DECLARE, cursors, IF, WHILE, LOOP | (not available) | In Python, a for loop over cursor.fetchall() does what a cursor loop does. |
| DELIMITER // | (not needed) | SQLite knows where a trigger's BEGIN ... END block ends. |
| CREATE VIEW | CREATE VIEW | The same, but SQLite views are read only. You cannot INSERT or UPDATE through one. |
| CREATE TRIGGER ... BEFORE INSERT SET NEW.status = UPPER(NEW.status); | CREATE TRIGGER ... AFTER INSERT BEGIN UPDATE attendance SET status = UPPER(NEW.status) WHERE attendance_id = NEW.attendance_id; END; | SQLite triggers cannot change NEW, so fix the row after it is inserted. The Lab 5 database in the playground has this trigger. |
| SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Bad score'; | SELECT RAISE(ABORT, 'Bad score'); | Refusing a row from inside a trigger. |
| IF NEW.score < 0 THEN ... END IF; | WHEN NEW.score < 0 | SQLite puts the condition on the trigger itself, before BEGIN. |
| CREATE USER, GRANT, REVOKE | (not available) | SQLite has no users. Whoever can open the file can read it. |
| MySQL | SQLite | Notes |
|---|---|---|
| pip install mysql-connector-python | (nothing to install) | sqlite3 is built into Python. |
| conn = mysql.connector.connect( host='localhost', user='root', password='...', database='school') | conn = sqlite3.connect('school.db') | SQLite needs only the file name. |
| cur.execute('... WHERE id = %s', (5,)) | cur.execute('... WHERE id = ?', (5,)) cur.execute('... WHERE id = :id', {'id': 5}) | The placeholder differs. Always use placeholders for values, never text pasted into the SQL, to prevent SQL injection. |
| conn.commit() | conn.commit() | The same: changes are not saved until you commit. |