Skip to content

Instantly share code, notes, and snippets.

@dpatlut
Created October 1, 2020 12:47
Show Gist options
  • Save dpatlut/286d3e1dc15a2ded79dd858315db7e84 to your computer and use it in GitHub Desktop.
Save dpatlut/286d3e1dc15a2ded79dd858315db7e84 to your computer and use it in GitHub Desktop.
SQL/Database Exit Ticket Solution

Day 07: SQL, PostgreSQL, Schema Design

You should be able to:

  • Explain what a database is, and why you would use one
  • Write SQL queries using some common keywords (SELECT, FROM, WHERE, ORDER BY, JOIN, etc)
  • Articulate what a primary key is
  • Articulate what a foreign key is, and why you would use one
  • Explain the differences between a 1-to-1, 1-to-many, and many-to-many relationship

A foreign key is

  • A column of one table that stores primary keys of another table ☑️
  • A unique identifier for each row in a table: This is a primary key not a foreign key

Match the example to the relationship type

One-to-one One-to-many Many-to-many Explanation
A person and his/her/their passport ☑️
An album and its songs ☑️ A song can be part of multiple albums (i.e., released in the original album but also be part of a greatest hits album)
An author and their books ☑️

What are examples of good primary keys?

  • Social Security Numbers ☑️
  • Birthdates
  • Phone Numbers ☑️
  • Fingerprints ☑️

Explanation: For SSN and Phone Numbers, these would be good but we can also think about how not everyone has these and perhaps the format of these identifiers may be different depending upon where the person is from. Fingerprints are great because they are unique to everyone and everyone has fingerprints

Choose the correct keywords to fill in the blanks in the following query to list everyone and their RSVP to dinner: ____ name, response ____ friends ____ responses ____ response DESC

  • SELECT, FROM, LEFT JOIN, ORDER BY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment