ENTITY-RELATIONSHIP.
The Entity-Relationship (ER) model is a diagrammatic approach used to describe the data and its
relationships in a database. It serves as a blueprint for designing and structuring a database by
identifying key components such as entities, their attributes, and the relationships between them.
Entity-Relationship (ER) models are fundamental in database design, providing a way to visually
represent data structures and their relationships.
COMPONENTS IN ER MODELS:
1. Entities
Definition: An entity is an object or concept that can be distinctly identified. It represents
a real-world object or a concept in the database.
Types:
o Strong Entity: Exists independently of other entities (e.g., a Customer or
Product).
o Weak Entity: Cannot exist without a related strong entity and relies on it for its
identity (e.g., Order Item depends on Order).
2. Attributes
Definition: Attributes provide more details about entities. They represent properties or
characteristics of entities.
Types:
o Simple Attribute: Cannot be divided further (e.g., EmployeeID, Name).
o Composite Attribute: Can be divided into smaller sub-parts (e.g., Address can
be divided into Street, City, Zip Code).
o Derived Attribute: Can be computed from other attributes (e.g., Age can be
derived from DateOfBirth).
o Multi-valued Attribute: Can have multiple values (e.g., PhoneNumbers for a
person).
3. Relationships
Definition: Relationships represent associations between entities.
Types:
o Unary (Recursive) Relationship: An entity is related to itself (e.g., an Employee
who manages other Employees).
o Binary Relationship: Involves two entities (e.g., Customer places Order).
o Ternary Relationship: Involves three entities (e.g., Student, Course, and
Instructor).
4. Cardinality
Definition: Cardinality defines the number of instances of one entity that can be
associated with an instance of another entity.
Types:
o One-to-One (1:1): An entity in set A is associated with at most one entity in set
B, and vice versa.
o One-to-Many (1): An entity in set A can be associated with multiple entities in
set B, but an entity in set B is associated with at most one entity in set A.
o Many-to-Many (M): Entities in set A can be associated with multiple entities in
set B, and vice versa.
5. Entity-Relationship Diagram (ERD)
Definition: A visual representation of entities, attributes, and relationships in a database.
Components:
o Entities: Represented by rectangles.
o Attributes: Represented by ovals.
o Relationships: Represented by diamonds.
o Lines: Connect entities to attributes and relationships.
6. Keys
Definition: Keys are attributes or combinations of attributes used to uniquely identify
entities or relationships.
Types:
o Primary Key: A unique identifier for each entity instance (e.g., StudentID for a
Student).
o Foreign Key: An attribute in one entity that references the primary key of another
entity to establish relationships.
o Composite Key: A combination of two or more attributes used to uniquely
identify an entity (e.g., a combination of OrderID and ProductID).
7. Normalization
Definition: The process of organizing data to reduce redundancy and improve data
integrity.
Normal Forms:
o First Normal Form (1NF): Ensures that the table is flat and does not have
repeating groups or arrays.
o Second Normal Form (2NF): Ensures that all non-key attributes are fully
functionally dependent on the entire primary key.
o Third Normal Form (3NF): Ensures that all attributes are only dependent on the
primary key and not on other non-key attributes.
ER Model to Relational Model
Transformation: The ER model is often translated into a relational schema for
implementation in a relational database management system (RDBMS).
o Entities become tables.
o Attributes become columns in the tables.
o Relationships are represented using foreign keys and join tables in the case of
many-to-many relationships.