Mastering Database Management

0 of 79 lessons complete (0%)

Relational Models

Understanding Entity-Relationship Diagrams (ERD)

You don’t have access to this lesson

Please register or sign in to access the course content.

Understanding Entity-Relationship Diagrams (ERD):

An Entity-Relationship Diagram (ERD) is a visual representation of the relationships among entities (tables) in a database. ERDs use various symbols to depict entities, attributes, relationships, and cardinality. Here are the key components of ERDs:

1. Entity:

  • An entity is a real-world object or concept that has data to be stored in a database.
  • Represented by a rectangle in an ERD.
  • Example: In a library database, “Book” and “Author” could be entities.

2. Attribute:

  • An attribute is a property or characteristic of an entity.
  • Represented by ovals connected to their respective entities.
  • Example: Attributes of the “Book” entity could include “Title,” “ISBN,” and “PublishYear.”

3. Relationship:

  • A relationship represents an association between two or more entities.
  • Represented by a diamond shape connecting related entities.
  • Example: A relationship between “Book” and “Author” signifies that an author can write multiple books.

4. Cardinality:

  • Cardinality defines the numerical relationships between entities in a relationship.
  • Expressed as “one” or “many” on each end of the relationship line.
  • Example: “One Author writes Many Books” signifies that an author can write multiple books.

5. Primary Key:

  • A primary key uniquely identifies each record in an entity.
  • Represented by underlining the attribute in the entity.
  • Example: “BookID” could be the primary key for the “Book” entity.

6. Foreign Key:

  • A foreign key is a field in one table that refers to the primary key in another table.
  • Represents relationships between tables.
  • Example: “AuthorID” in the “Book” entity could be a foreign key referencing the “Author” entity.

Example ERD:

Consider a simple library database with entities “Book” and “Author”:

  • The rectangles represent entities (“Book” and “Author”).
  • The ovals represent attributes of each entity (“BookID,” “Title,” “ISBN,” etc.).
  • The diamond shape represents the relationship (“writes”) between “Author” and “Book” entities.
  • The crow’s foot notation indicates cardinality, specifying that “One Author writes Many Books.”

How to Read an ERD:

  1. Entities:
    • Identify entities and their attributes.
    • Understand what information is stored in each entity.
  2. Relationships:
    • Identify relationships between entities.
    • Understand the cardinality (one-to-one, one-to-many, many-to-many).
  3. Attributes:
    • Understand the attributes of each entity.
    • Recognize primary keys and foreign keys.

ERDs provide a clear and concise way to represent the structure of a database and the relationships between its entities. They are valuable tools for database designers, developers, and stakeholders to understand and communicate the database schema.