SQSQL · Lesson 2 of 8
CREATE, INSERT, UPDATE, DELETE
Reading data is half the story. The other half: creating tables and changing what's in them. These four statements are called CRUD — Create, Read, Update, Delete.
CREATE TABLE defines a new table: each column gets a name and a type. Common types are INTEGER, REAL (floating point), TEXT, and BOOLEAN. Constraints like NOT NULL and UNIQUE enforce rules on the data so garbage can't get in.
⚠ Warning
UPDATE and DELETE without a WHERE clause affect EVERY row in the table. 'DELETE FROM students;' empties the whole table, no confirmation asked. Always write the WHERE first, and consider running it inside a SELECT to preview which rows will be hit.
UPDATE and DELETE without a WHERE clause affect EVERY row in the table. 'DELETE FROM students;' empties the whole table, no confirmation asked. Always write the WHERE first, and consider running it inside a SELECT to preview which rows will be hit.