Relationship
The relationship in the ER model is represented using a diamond-shaped box.
Example:
‘Buys’ is a relationship between customer entity and products. This relationship can be read as ‘A customer buys a product/products.
Therefore, a relationship is a way to connect multiple entities.
- When a customer buys a product, there is a timestamp associated with it, so the attribute “Time” will be an attribute of ‘Buys’.
- All the database concepts can be easily understood from the concepts of sets and relations.
- According to the Set-theoretic perspective, it will be represented as
By interpreting this, we can understand that many customers can buy the same type of product and many products can be bought by many customers. And there are some products which are not bought by any customer and there are some customers who do not buy any product.
According to the Relation/table perspective or relational model:
It can be represented as
As the relationship is many to many(M: N) between customer and product, therefore we require separate tables/ relations for ‘buys’.
In buys relation, Cust_id and Prod_id are the foreign key to the customer and product.
What is Mapping Cardinalities in ER Diagrams
In a Database Management System (DBMS), mapping cardinalities explains how entities (tables) in a database schema relate to one another. They provide the number of instances of one entity that can be linked to the number of instances of another entity via a certain kind of relationship, such as many-to-many, one-to-one, or many-to-many. Designing exact links between tables, preserving data integrity, and simulating actual business operations in a database all depend on the mapping of cardinalities. They are a cornerstone of database design’s entity-relationship paradigm.
Whenever an attribute of one entity type refers to another entity type, then some relationship exists between them.
Example:
- The attribute Manager of the department refers to an employee who manages the department.
- In the ER model, these references are represented as relationships.