DEV Community

Raphael Njeri
Raphael Njeri

Posted on

Relationship Schemas and Joins in Data Modeling

This week I learned about relationship schemas and joins, and I now understand why they are important when working with databases. Before this topic, I thought all the data could just be stored in one table, but I have realized that this is not the best approach because it creates a lot of repeated information and makes the database harder to manage.

From what I have understood, a relationship schema is simply the way different tables in a database are connected. Instead of putting everything in one table, the data is separated into different tables depending on what it represents. For example, students, teachers, and payments can each have their own table, and then they are linked using IDs. This makes the data more organized and easier to update.

I also learned that there are different types of relationships. A one-to-one relationship is where one record is connected to only one other record. A one-to-many relationship is the one I found easiest to understand because one teacher can teach many students, but each student is assigned to only one teacher. There is also a many-to-many relationship where one student can take several courses and one course can have many students. In such a case, another table is needed to connect the two.

Another concept I learned is joins. Joins are used when information is stored in different tables but we want to see it together. The INNER JOIN only shows records that match in both tables. The LEFT JOIN returns everything from the first table even if there is no matching record in the second table. The RIGHT JOIN does the opposite, while the FULL OUTER JOIN returns all records from both tables whether they match or not.

As I continue practicing data modeling and using Power BI, I can now see why relationship schemas and joins are necessary. They help in creating a proper data model instead of using one flat table. This makes reports more accurate, reduces duplicated data, and makes it easier to analyze information. Although I still need more practice, I now have a much better understanding of how tables relate to each other and how joins help retrieve data from those related tables.

Top comments (0)