CREATE TABLE and constraints
A table definition describes what can be stored. Start with the row meaning, then choose columns and rules.
Define a table
CREATE TABLE creates a database object. Write its name followed by the column definitions in parentheses. The practice database is reset before each run.
Types and required values
INTEGER stores whole numbers and TEXT stores text in this lab. NOT NULL requires a value. SQLite has flexible typing; stricter databases can reject values SQLite converts.
Keys and constraints
PRIMARY KEY identifies each record. UNIQUE prevents repeated non-NULL values. CHECK validates a rule such as quantity >= 0. Foreign keys connect records to an existing table.
Verify the definition
Use PRAGMA table_info(table_name) in SQLite to inspect column names, types and required values. Creating a table is different from inserting rows into it.