Mada za sehemu hiiImplementing database modelling and relationshipsMada 3
- Designing relations
- Designing entity relationships
- Designing entity relationship diagrams
An Entity-Relationship (ER) diagram is a visual tool that helps us plan and design a database by showing how different pieces of information are connected. Before we build a database to store data on a computer, we first draw an ER diagram to understand what data we need, what groups the data belongs to, and how these groups relate to each other.
An entity is a real-world object or concept that has its own data and can be identified uniquely. In a database, each entity becomes a table.
Types of Entities
- Strong entity: Can exist on its own and has a primary key (unique identifier) — for example, a STUDENT can exist without depending on another entity.
- Weak entity: Cannot exist on its own and depends on another entity — for example, a BOOK_COPY depends on the BOOK entity.
How to Identify Entities
Ask yourself: "What things do I need to store information about?" These become your entities.
An attribute is a characteristic or property of an entity. Each attribute holds a piece of data about the entity.
Types of Attributes
- Simple attribute: Cannot be divided — for example,
ageorphone_number. - Composite attribute: Can be split into smaller parts — for example,
full_namecan be split intofirst_nameandlast_name. - Key attribute: A unique identifier for each instance — for example,
student_idorproduct_code. - Multivalued attribute: Can hold multiple values — for example,
phone_numbers(a student may have more than one).
A relationship describes how two or more entities are connected to each other.
Types of Relationships
- One-to-One (1:1): Each record in Entity A relates to only one record in Entity B, and vice versa. Example: One STUDENT has one ID CARD.
- One-to-Many (1:N): One record in Entity A relates to many records in Entity B, but each record in Entity B relates to only one record in Entity A. Example: One TEACHER teaches many STUDENTS.
- Many-to-Many (M:N): Records in Entity A can relate to many records in Entity B, and records in Entity B can relate to many records in Entity A. Example: A STUDENT takes many SUBJECTS, and a SUBJECT is taken by many STUDENTS.
Cardinality and Participation
- Cardinality tells us the maximum number of times an entity can participate in a relationship.
- Participation tells us whether an entity must participate in a relationship (total participation) or can optionally participate (partial participation).
Imagine you are designing a database for a small duka in Arusha. You need to keep track of products and the customers who buy them.
Step 1: Identify the Entities
- PRODUCT — items sold in the duka
- CUSTOMER — people who buy items
- ORDER — a purchase made by a customer
Step 2: Identify Attributes
- PRODUCT:
product_id(key),product_name,price,quantity_in_stock - CUSTOMER:
customer_id(key),customer_name,phone_number - ORDER:
order_id(key),order_date,total_amount
Step 3: Identify Relationships
- A CUSTOMER places many ORDERs (one-to-many)
- An ORDER includes many PRODUCTs (many-to-many, which would later become a linking table)
Step 4: Draw the ER Diagram
+------------+ +------------+ +------------+
| CUSTOMER | | ORDER | | PRODUCT |
+------------+ +------------+ +------------+
| PK customer_id| | PK order_id | | PK product_id|
| customer_name |------| order_date | | product_name |
| phone_number | | total_amount| | price |
+------------+ +------------+ | quantity |
| | customer_id|FK| +------------+
| +------------+ |
| | |
+-----------------+-----------------+
places contains
The lines show the relationships: one CUSTOMER can place many ORDERs, and each ORDER can contain many PRODUCTs.
- Understand the problem — Read the case study or scenario carefully. Ask: What data needs to be stored?
- Identify entities — List the main objects or concepts. These are usually nouns.
- List attributes — For each entity, write down all the properties or characteristics.
- Choose key attributes — Identify which attribute uniquely identifies each record.
- Determine relationships — Look for connections between entities. Ask: How does one thing relate to another?
- Identify cardinality — For each relationship, decide if it is one-to-one, one-to-many, or many-to-many.
- Draw the diagram — Use rectangles for entities, ovals for attributes, and diamonds for relationships. Connect them with lines.
- Review and refine — Check with peers to ensure the diagram accurately represents the scenario.
- Use clear, standard notation (Chen notation or Crow's Foot notation are common).
- Label each relationship with a verb (e.g., "enrolls," "sells," "owns").
- Ensure every entity has a key attribute.
- Review your diagram against the requirements of the system you are modelling.
In Tanzania, small business owners such as market vendors in Kariakoo or shop owners in Mwanza can use ER diagrams to plan a simple inventory database. For example, a duka owner can design an ER diagram to track which products (entities) have which prices (attributes), which customers (entities) bought which items, and how these connect — helping them manage stock and sales more efficiently using software or mobile apps.
Jinsi utakavyotathminiwaTathmini ya mchakato · Tathmini ya matokeo · Tathmini ya maarifa
Tathmini ya mchakato
- Create ER diagrams based on provided scenarios.
- Use standard notations (e.g. Chen, Crow's Foot).
- Include attributes, keys, and relationships.
Tathmini ya matokeo
A complete and accurate ER diagram illustrating entities, relationships, and attributes in a logical structure is designed.
Tathmini ya maarifa
Detailed knowledge of:
Method used: The student should explain how to:
- create and interpret ER diagrams.
Principles: The student should explain the principle of:
- diagrammatic representation of databases.
Theories: The student should explain:
- Types of notations (e.g., Chen, Crow's Foot).
Circumstantial knowledge:
Detailed knowledge about:
- Common pitfalls in diagram design.
Swali
What is an entity in an Entity-Relationship (ER) diagram?
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuulizaMajadiliano
Hakuna maswali bado