DEV Community

Author
Author

Posted on

Join Table

When modelling data for SQL, a useful tool for data engineers is the Join Table. A Join Table reduces redundancy in relational databases by defining the relationship between tables as an entity. In the case of many-to-many relationships, Join Table is the best practice.

Here is a simple join table written in the Ruby on Rails schema DSL (domain specific language.) The use case is a student portfolio which contains Projects, and each project is made with a number of Technologies.

create_table "projects" do |t|
    t.string   "title"
    t.string   "image"
    t.text     "description"
    t.string   "repository_url"
    t.string   "demo_url"
    t.text     "role"
 end

create_table "projects_technologies" do |t|
    t.integer  "project_id"
    t.integer  "technology_id"
    t.index ["project_id", "technology_id"], name: "index_projects_technologies_on_project_id_and_technology_id", using: :btree
end

create_table "technologies" do |t|
    t.string   "name"
end
Enter fullscreen mode Exit fullscreen mode

The Join Table in this exercise is projects_technologies.


Comment below if you're interested in Join Tables! If you're proficient in it, Come join us at Salvation! We're Saving The World, and making plenty of tables along the way!

~ ATHS

Top comments (0)