INTERACTIVE LECTURES
Build and change a database
Guided class activity · apply the ideas from the full SQL lessons.
Open the detailed lessons for this activity
Detailed lessons in this module
Open the full explanations, examples, and SQL exercises directly.
Preparing for Lab 10 · After practice, try the team challenge.
Opening your saved work…
Sign in to save across devices → · Download your guest work before switching accounts.
Design constraints and verify the schema
Step 2 of 9 · Database: Northshore Coffee
READ & UNDERSTAND
CREATE TABLE defines the columns and constraints; ALTER changes a table’s structure; DROP removes the table. These affect a different level of the database from selecting or updating rows.
A primary key distinguishes rows. NOT NULL requires a value. A foreign key describes a relationship, but enforcement depends on the database configuration. Do not infer enforcement from a line drawn in a schema diagram.
Use the CREATE, ALTER, and DROP workshops below to run changes on their own independent fixtures. Inspect the live schema before and after each change.
Worked example
SELECT id, name FROM shops ORDER BY id;
The example preserves the shop identifier alongside its name. A future orders row must refer to a valid shop identifier, not a shop name copied into a numeric field.
Inspect declared relationships in Quick schema, then test enforcement with a deliberately invalid row in the separate change workshop or assigned desktop environment.
Your question
Return shop_id and employee_id for the first five orders ordered by id. Identify the two relationships a future import must preserve.
Explain your evidence
What invalid row would you attempt in a disposable database to test a proposed constraint?
Try a query to unlock the worked-answer discussion.
Query results
Predict the result, then run your query.Predict the result, then run your query.
Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.
Explore this query freely in the playground ↗Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.