Design and build your own database tables from scratch. This SQLite-focused lesson teaches columns, constraints (PRIMARY KEY, NOT NULL, UNIQUE, CHECK, FOREIGN KEY), ALTER TABLE changes, and safe table removal with DROP TABLE.
Build a new table by defining its name, columns, and data types. This is where database design begins ā deciding what data to store and how to structure it.
sqlite3 ecommerce.db.headers on.mode columnCREATE TABLE wishlists (id INTEGER PRIMARY KEY AUTOINCREMENT, customer_id INTEGER NOT NULL, product_id INTEGER NOT NULL, added_date TEXT NOT NULL DEFAULT (date('now')), note TEXT);.schema wishlistsCREATE TABLE defines a new table with a name and a list of columns. Each column has a name and a type (INTEGER, TEXT, REAL). This wishlists table will let customers save products they want to buy later. The column definitions read naturally: `id` is an auto-incrementing integer primary key, `customer_id` and `product_id` are required integers, `added_date` defaults to today, and `note` is optional text. Think of CREATE TABLE as designing a spreadsheet's column headers and rules before entering any data.
The CREATE TABLE command completes silently. The .schema wishlists command displays the full table definition, confirming all columns, types, and constraints are in place.