database lab change data safely · resets every run
Database Lab
Run database experiments in a disposable copy. Nothing changes the shared Runtime dataset.
19 experiments fit Retail. Other datasets offer others.
Create a table
Define a table with typed columns, a primary key, required values and a link to an existing table.
- what you'll try
- Create a customer_notes table linked to customers, then read its column definitions back from the database.
- what you should see
- One row per column: note_id is the primary key, customer_id and note are required (not_null = 1), and created_at defaults to the current time.
tables involved
- customers 848 rows
how the lab works
Every Run starts from the original Retail database. Tables you create and rows you change exist only for that run. End the script with a SELECT to see the effect. Your SQL is saved in this browser.
all Retail tables
categories17 rows · 3 columns
One product category (for example Christmas or Kitchen). Products are grouped into these from their descriptions.
- category_id
Category key
- category_name
Category label
- department
Broader group of categories; Non-merchandise covers fees and accounting adjustments
products5,304 rows · 6 columns
One product in the catalog (one stock code). Some products never appear on invoices in this sample.
- stock_code
Product code; letter codes often mark fees, samples, or adjustments
- description
Usual product name; NULL if the source never described this code
- category_id
Category for this product; NULL if it has no description
- list_price
Typical sale price in GBP; NULL if never sold at a positive price
- first_sold_at
First time this product appeared on any invoice
- is_merchandise
1 for goods, 0 for postage, fees, samples, and adjustments
customers848 rows · 4 columns
One known customer. Anonymous (walk-in) invoices have no matching customer row.
- customer_id
Customer number from the source
- country
Country on the customer’s first invoice
- region
United Kingdom, Europe, or Rest of World
- first_order_at
Time of the customer’s first invoice
orders6,722 rows · 6 columns
One invoice: a sale, a cancellation (credit note), or an accounting adjustment.
- order_id
Invoice key
- invoice_no
Source invoice number; C = cancellation, A = adjustment
- customer_id
Customer; NULL for anonymous invoices
- ordered_at
Invoice time
- country
Delivery country on the invoice
- order_type
sale, cancellation, or adjustment
order_items125,613 rows · 7 columns
One line on an invoice. Cancellation lines use negative quantities.
- order_item_id
Line key
- order_id
Invoice this line belongs to
- line_number
Position on the invoice, starting at 1
- stock_code
Product code
- description
Text printed on this line; can differ from the catalog name
- quantity
Units sold; negative on cancellations and stock adjustments
- unit_price
Price per unit in GBP
payments5,423 rows · 6 columns
One payment attempt for a sale invoice. Payments are modeled; the original source has no payment ledger.
- payment_id
Payment attempt key
- order_id
Sale invoice being paid
- paid_at
When the attempt happened
- method
card, bank_transfer, paypal, or account_credit
- amount
Attempted amount in GBP
- status
captured or failed; only captured attempts count as paid
returns1,996 rows · 6 columns
One cancelled invoice line, linked to the earlier sale it reverses when that sale is in the data.
- return_id
Return key
- order_item_id
The cancellation line being returned
- original_order_id
Earlier sale of the same product to the same customer; NULL if none is found
- quantity_returned
Units returned (positive)
- refund_amount
Credit value in GBP
- returned_at
When the cancellation invoice was issued
customer_history1,685 rows · 7 columns
One version of a customer’s segment and country over time. A new row starts when either changes.
- history_id
Version key
- customer_id
Customer
- segment
occasional, regular, or key_account based on recent net sales
- country
Country for this version
- valid_from
First date this version applies
- valid_to
First date it no longer applies; NULL if this is the current version
- is_current
1 if this is the customer’s current version