Demo mode This site is not live. It is currently being tested and developed. Nothing on here represents an offer.
← Exit course WEB-301 Full-Stack Web Development with PHP and Laravel
Course progress, 0 of 17 parts done0%

Review Study Aid

Download as PDF

The points to fix in memory before the self assessment.

Definitions you must be able to give

  • A table holds one kind of thing, a row is one of those things, and a column is one kind of fact with one data type.
  • A primary key identifies every row and is unique and never NULL.
  • A foreign key holds another table's primary key, and the database guarantees the row it names exists.
  • A constraint is a rule the database enforces on every change, from every program.
  • A transaction is a group of statements that succeed or fail as one.
  • NULL means a missing or unknown value, not zero or empty text.

Commands and syntax to know

  • psql -h localhost -U walks_app -d mandlas_walks connects to the Walk Office database.
  • \d walks describes a table, \dt lists tables, \x toggles expanded display and \i file.sql runs a file.
  • psql -1 -v ON_ERROR_STOP=1 -f sql/schema.sql -f sql/seed.sql runs files as one transaction and stops at the first error.
  • id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY is the id column of every Walk Office table.
  • INSERT INTO walks (slug, name, ...) VALUES (...), (...) RETURNING id; adds rows and reports their new ids.
  • A query's clauses come in the order SELECT, FROM, WHERE, ORDER BY, LIMIT, OFFSET.
  • COALESCE(phone, '-') shows a hyphen where the phone is NULL.

Rules and limits

  • Money is stored as whole rand in an integer or as numeric, never as real or double precision.
  • numeric(4,1) holds at most 999.9, and integer division drops the fraction, so 7 / 2 is 3.
  • BETWEEN includes both ends, and LIKE is case-sensitive while ILIKE is not.
  • Without ORDER BY, rows come back in no guaranteed order.
  • A CHECK passes when its condition is unknown, so pair checks with NOT NULL.
  • Inside a failed transaction, PostgreSQL accepts only ROLLBACK.
  • Africa/Johannesburg is two hours ahead of UTC all year, shown as +02.

Distinctions not to confuse

  • Single quotes hold text values, and double quotes hold names.
  • = NULL is never true, while IS NULL finds missing values.
  • timestamptz stores an exact moment, while timestamp stores a clock time with no zone.
  • ON DELETE RESTRICT refuses the delete, while ON DELETE CASCADE deletes the referring rows too.
  • || gives NULL if any part is NULL, while concat() treats NULL as empty text.
  • COMMIT saves a transaction's changes for everyone, while ROLLBACK discards them.