Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Last active August 29, 2015 14:14
Show Gist options
  • Save vanderhoop/0f1ce58672d1ab1d17fc to your computer and use it in GitHub Desktop.
Save vanderhoop/0f1ce58672d1ab1d17fc to your computer and use it in GitHub Desktop.

Get Normalized

Peter Lai thinks you've done a great job on the shopping_db database, but now he wants you to normalize our data, ie split the repetitive parts into their own tables.

Directions

  1. Within shopping_db, create a table, stores for holding your store data. Each store should have:
  • an auto-incrementing primary key of id
  • a name attribute
  • a slogan attribute
  1. Create an entry in the stores table for each of the stores that appears in the receipts table, passing in borderline creative dummy data for slogan
  2. Now add a store_id column to the receipts table.
  3. Now update the records in the receipts table so that each record gets the appropriate store_id value.
  • Example: If Sears is assigned an id of 3 in the stores array, update all the reciepts for Sears purchases with a store_id of 3.
  1. Now drop the store column in the receipts table. It's redundant and less informative than our new data-rich table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment