# Matrix Diagrams

Matrix diagrams are an effective way for checking complex many-to-many database relationships. Everything about Matrix Diagrams explained here.

## Purpose

• It is useful to know more than one way to discover relationships.
• Using a matrix diagram, especially when you are dealing with many entities, is a good way to make sure that you haven’t missed any relationships.

• “I work for a travel agency. I keep a record of the countries that our customers have visited and the landmarks they’ve seen in each country. It helps us customize tours for them.”
• We can use the matrix diagram to uncover relationships.

Sometimes when you are working with many entities, it’s hard to know where to start defining relationships. What if you miss something? How do you make sure that you haven’t missed some combination of entities? Maybe you’ve missed a relationship!

We are going to learn another useful way to identify relationships.

## Matrix Diagrams

• To avoid confusion, be consistent in writing to and reading from the matrix only in one direction.
• Relationships discovered via the matrix diagram are then drawn on the ERD.
• Matrix diagrams do not show optionality and cardinality.

Note: that if an entity is related to itself, a cell on the diagonal will also contain a relationship.

• Each COUNTRY may be visited by one or more TRAVELERs.
• Each TRAVELER may visit one or more COUNTRY.

After completing the matrix diagram, you should draw the relationships on the ERD to specify optionality and cardinality by first writing the relationships in ERDish, then draw the ERD. The completed ERD should match the relationships uncovered in the Matrix Diagram.

• Each TRAVELER may have seen one or more LANDMARKs.
• Each LANDMARK may be seen by one or more TRAVELERs.
• Each LANDMARK must be located in one and only one COUNTRY.
• Each COUNTRY may be the location of one or more LANDMARKs.

Note that there are M:M (Many to Many) relationships between TRAVELER and COUNTRY, and between TRAVELER and LANDMARK. These are valid relationships, but they will be discussed in more detail later.

## Terminology

Key terms used in this tutorial included:

• Matrix diagram

## Summary

In this tutorial, you should have learned how to:

• Identify relationships using a matrix diagram
• Draw an ERD from a matrix diagram