In this tutorial, we will learn about database entities and relationships. Relational databases store information about entities and how these entities are related.
In database modelling, an entity is used to denote real-world thing, person,place, concept, etc for which we want to store data in the database. For example, bank account, bank customer are entities. Database table is used to store data that represents entities of one particular kind. Each row represents data of one instance of the entity. For example, the Customers table is used to store information of customers. Each row represents the data of one customer.
A relationship is an association between entities. It is the link between the database entities and is used to denote how entities relate to each other. A relationship is defined y a diamond-shape symbol in an ER diagram.
Relationships can be categorized according to how entities can be involved in the relationship::
- One-to-One ( 1:1)
- One-to-Many( 1:M)
- Many-to-One( M:1)
- Many-to-Many( M:N)
A one-to-one relationship exists when a single entity is linked with another single entity. For example, a single person can have a single passport.
Let’s consider the bank example. A customer can have more than one bank account. So, the relationship between customers and bank accounts is a one-to-many relationship. Note that it is even possible that a customer has no bank account at all. The term many refers o the maximum number of accounts the customer can have.
For example, let’s consider students and courses in a university. The entities in the relationship are Student and Course. A student can attend more than one course. Conversely, a course can be attended by many student. So, the relationship between students and courses is a many-to-many relationship.
MySQL Tutorials on this website:
For more information on MySQL Database: