Entities Attributes and Relationships are key elements in ER diagrams.
Entity
- An entity is a real world object of independent of another.
- In an ER diagram, entities are typically represented as rectangles as shown above.
- Examples – Student, Teacher, Employee, Product, Order
Mainly there are 2 types
- Strong Entity
- A strong entity is an entity that has a primary key attribute
- It is not dependent on any other entity.
- It can be uniquely identified by its own attributes.
- Weak Entity
- A weak entity is an entity that doesn’t have a primary key attribute of its own.
- Its existence depends on another entity, called the owner entity.
- Weak entities are typically identified by a partial key, and their primary key includes the primary key of the owner entity.
Best describes of Attributes
- In ER diagrams, attributes are properties or characteristics that describe the entities in the database.
- There are different types of attributes, each has a specific purpose when defining the database structure.
- Here are common types of attributes in an ER diagram.
- Simple Attribute
- A simple attribute cannot be divided any further, that means it is atomic. It represents a single value associated with an entity.
- Example, Name, Age, studentID, address
- Composite Attribute:
- A composite attribute is an attribute that can be divided into smaller sub parts.
- Example, name attribute can be composed of sub parts like first name, middle name and last name.
- Derived Attribute
- A derived attribute is an attribute whose value can be derived or calculated from another attribute (from stored attribute).
- It is not stored physically because it can be computed when needed.
- Example, “Age” might be a derived attribute based on the “Date of Birth.”
- Multi valued Attribute
- A multi-valued attribute can keep multiple values for a single entity.
- For instance, an entity “Employee” can have a multi valued attribute called “Phone Number” to store multiple phone numbers associated with that Employee.
- Key Attribute
- A key attribute is an attribute that can uniquely identify an entity.
- In an ER diagram, key attributes are often underlined.
- Composite Key
- A composite key is a key that consists of two or more attributes for the primary key.
- It is used when a single attribute is not sufficient to uniquely identify an entity.
- Composite keys are represented by underlining the combination of attributes in an ER diagram.
Relationship
- In ER diagrams, a relationship is a connection between two or more entities.
- It describes how data is related and interconnected in a database.
- Relationships are often categorized into different types based on the cardinality (example., 1:1, 1:M and M:N).
Weak Relationship
- A weak relationship is a type of relationship where the existence of one entity (the child entity) depends on another entity (the parent entity).
- This child entity has a primary key that is partially or totally derived from the parent entity. Without the parent entity, the child entity may not be uniquely identified.
- To represent a weak relationship, you can use a double diamond shape in the connecting line between the parent and child entities. Additionally, the child entity may have a double-lined border to indicate its weakness.