Key types

  • super key
    • value(s) that can identify a row in a table
  • candidate key
    • super key without unneccessairy attributes
  • primary key
    • candidate key selected by DB admin as a unique identifier
    • max 1
  • alternate key
    • candidate keys which are not primary keys
  • foreign key
    • primary key from another table
  • composite key
    • candidate/primary key that consists of more than 1 attribute

Constraints

= rules for data in a table (e.g. columns)

📖 Example:

  • primary/foreign key
  • not null
  • default (sets default value)
  • check (checks if condition met)
  • create index

Best practices for planning

  • normalize data
  • place constraints
  • document it
  • create indexes

Postgres

  • Definition
    • precision = total num of digits
    • scale = num of digits to right of ,