Entity-Relationship Diagram
Tags: database, computerscience
Published: 2021-06-05 11:44:37

It is a high level data model diagram which defines the conceptual view of the database. It indicates the relation among entities.
Before making the actual database, first the ER-diagram is drawn to show the relations and many more things.

**Components of ER Diagram:**

**1) Entity**
i) It is a real-world object.
ii) It can be physical.
iii) It can be logical. 

**Entity Set** - It is a set (or collection) of entities of the same type which share the similar properties or attributes.

**An entity can be characterized into two types:**

**i) Strong Entity** -
-> It has a Primary Key.
-> It is not dependent.
-> They are shown in single rectangle
**ii) Weak Entity** - 
-> It doesn't have the sufficient attributes to form Primary Key.
-> It is dependent on the Strong Entity.
-> They are shown in double Rectangle.

**Example**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdmpsu8wk0c9u4dvc8fb.png)

**Total Participation** - Weak Entity always has total participation with the Relationship. This means that each entity in the entity set must compulsorily participate in at least one relationship instance in that relationship set.

**2) Attributes** - They are the properties that describe the entity.

**An attribute can be characterized into:**

**1) Simple Attributes:** They are represented by oval.

**Example**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ds2kv7b3qxi200ktw78.png)

**2) Multi-valued Attributes:** Multiple values for a single attribute. They are represented by double oval.

**Example**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqr3pickbhr7yn5028dp.png)

**3) Single-Valued Attributes:** Each and every entity will have only one value.
**Example** - ID

**4) Composite Attributes:** Those attributes that can be divided further.

**Example**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n2npqhfjv7i8s9qlw8ex.png)

**5) Derived Attributes:** Those attributes whose values are derived from another attribute. They are represented by dotted oval.

**Example**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t90qaescirb65ji94h2y.png)

Age is a derived attribute since age can be derived from the Date of Birth.

**6) Key Attribute:** Attribute which can uniquely define the whole tuple is called a Key Attribute.

**Example**- ID
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q319zng3m8t6i3tz5qvb.png)

**3) Relationship**
It indicates how each and every entity is related with every other entity.

**Degree of Relationship:** A relationship where a number of different entity set participate is called as degree of a relationship.

**Degree of relationship can be categorized into the following types:**

**1) Unary** - Only one Entity set participates in a relationship.

**Example**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qq1eyfi3552nsgzgu21.png)

**2) Binary** - Two Entity Sets participate in a relationship.

**Example**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/deoyrprq9y0om6re6kuc.png)

It is further divided into four types:
**i) One-to-One:**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/deoyrprq9y0om6re6kuc.png)

**ii) One-to-Many:**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g4apt41dt4snydomuchk.png)

**iii) Many-to-One:**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rtpzf4hz3rpjig61btcx.png)

**iv) Many-to-Many:**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atqcu2c8dg0bi1e6ycll.png)

**3) Ternary** - When three entity sets participate in a relationship.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eixexawkf2o93u6hzt2p.png)

**4) n-ary** - When more than three entity set involves in a relationship, it is called **n-ary relationship**.

**Summary of ER-Diagram Symbols**
1) Entity or Strong Entity:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpts8dv15vbulbujx7ku.png)

2) Weak Entity:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nhrzuztb0qghbig8gwu.png)

3) Attribute:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogtg2c83cqjk2xboj4v5.png)

4) Multi-valued Attribute:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vx9phpeyuugwzw2xt04.png)

5) Relationship:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hq89725af4rfzp9take.png)

6) Weak Relationship:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk2nitsakbcid597z6rz.png)

That's all for today.
Thank You.
Hope to see you in my next article...