Code Monkey home page Code Monkey logo

sql-table-relations-lab's Introduction

Sql Table Relations Lab

In this lab, we're going to work on establishing relationships between tables. You should have already read about table relations and foreign keys in the SQL Book. Let's practice making tables that are related to one another through foreign keys.

The Domain Model

Let's create a few tables:

  1. schools
  2. courses
  3. students

Using Foreign Keys

One school might have one or more courses, so it's fitting to have a separate table for courses, instead of having multiple columns on the schools table for each potential course. To make the connection between a school and it's courses, we'll make a column on the courses table called school_id, where each record is going to point to a corresponding record in the schools table (via the foreign key school_id matching a school's id).

Making a Join Table

Students can take multiple courses and courses can have multiple students enrolled. The way to represent this will be through a join table. Let's call it enrollments. Join tables are sometimes just referred to by combining the names of the two tables they're joining (so in this case, it could be students_courses), but we're going with enrollments because that just makes sense. Additionally, an enrollment is an actual object: we might add columns/attributes to the table later on.

Todo

Let the spec/create_spec.rb guide you on how the tables look. Write your CREATE statements in lib/create.sql.

Resources

View Sql Table Relations Lab on Learn.co and start learning to code for free.

sql-table-relations-lab's People

Contributors

ahimmelstoss avatar fislabstest avatar fs-lms-test-bot avatar sarogers avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mooseboost

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.