Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Last active January 11, 2016 14:43
Show Gist options
  • Save vanderhoop/bbff2ff1bd47755110d5 to your computer and use it in GitHub Desktop.
Save vanderhoop/bbff2ff1bd47755110d5 to your computer and use it in GitHub Desktop.

Schema Exercise

Partner up, and on your whiteboard tables, write out schema declarations for Animals and Employees, discussing what datatype and contraints best suit each attribute. Once you feel confident in your schemas, type them up in a .sql file and add it to your wdi database.

Animals Schema

Design a schema such that each animal has the following attributes:

  • species
  • sex
  • is_carnivore

Employees Schema

Design a schema such that each employee has the following attributes:

  • name
  • age
  • title
  • badge_number

Example Schema:

CREATE TABLE jedis (
  id                   SERIAL      PRIMARY KEY,
  name                 VARCHAR(50) NOT NULL,
  lightsaber_color     VARCHAR(50) NOT NULL,
  years_training       INTEGER     NOT NULL,
  social_security      VARCHAR(12) UNIQUE,
  tempted_by_dark_side BOOLEAN     NOT NULL,
  temptation           VARCHAR(50) NOT NULL
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment