BBampaa

Lessons › SQL › Chapter 7: Creating and changing tables

SQL lesson

CREATE TABLE

A table holds your data in columns. CREATE TABLE makes a new, empty one. You give it a name, then list each column with the kind of data it holds. TEXT holds words, INTEGER holds whole numbers, NUMERIC holds money and decimals, and DATE holds dates.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Make a new, empty table

CREATE TABLE targets (
  store TEXT,
  month DATE,
  target NUMERIC
)

Result:

storemonthtarget

Step by step

  1. Makes a new table called targets.
    CREATE TABLE targets (store TEXT, month DATE, target NUMERIC)
  2. A name, then its kind, with commas between the columns.
    CREATE TABLE targets (store TEXT, month DATE, target NUMERIC)

Practice

Try each one in your head first, then open the answer.

1. Make a table called targets with store (TEXT), month (DATE) and target (NUMERIC).
CREATE TABLE targets (store TEXT, month DATE, target NUMERIC)
2. Make a table called returns with return_id (TEXT), order_id (TEXT) and refund (NUMERIC).
CREATE TABLE returns (return_id TEXT, order_id TEXT, refund NUMERIC)
3. Make a table called staff with staff_id (TEXT), full_name (TEXT) and start_date (DATE).
CREATE TABLE staff (staff_id TEXT, full_name TEXT, start_date DATE)
4. Make a table called stock_counts with product_id (TEXT), store (TEXT) and units (INTEGER).
CREATE TABLE stock_counts (product_id TEXT, store TEXT, units INTEGER)
5. Make a table called promo_codes with code (TEXT), discount (NUMERIC) and ends_on (DATE).
CREATE TABLE promo_codes (code TEXT, discount NUMERIC, ends_on DATE)

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed