0% found this document useful (0 votes)
3 views

IT212- Lecture 2

Uploaded by

ANDROID Locu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

IT212- Lecture 2

Uploaded by

ANDROID Locu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Relational Database Model

By: Mrs Memory Mumbi Lumbwe


Dip.TM, BSc. MIS, MBA & MSc. CS

28/02/2025
Relational Databases
• First proposed by Dr. E.F. Codd of IBM Research in 1970
• Represent database as a collection of relations.
• Each relation looks like a table of values.
• Represent database as a collections of relations.
• Relational database matches data by using common characteristics
found within the data set.
Relational Databases Implementation
conceipts
• Implemented through Relational DBMS (RDBMS)
• RDBMS manage the complexity of physical implementation.
• Users see database as a collection of tables in which data are stored.
• Tables are also known as Relation.
• Tables contains Attributes.
• Attributes are a set of characteristics of the table.
• Tables are related to each other through some shared attributes.
• The relationship type is shown in Relational Schema.
Example of a Relational Database
Components of a Relation
• Entity
• Attribute/Column (Field)
• Domain
• Degree
• Record/Row (Tuple)
• Cardinality
Entity
• Things or object in real world with independent existence.
• An entity may be object with:
• physical existence : person, car, house, employed, etc.
• conceptual existence : job, course, event.
Attribute (Field)

• Each entity has certain characteristics known as attributes.


• Named column of relation.
• Example : an EMPLOYEE entity maybe describe by employee's name,
age, address, salary and job.
• Used to hold information about the objects to be represented in
database
Simple & Composite Attributes
• Simple Attributes
• Attribute that cannot be further divided
• Simple (Atomic) attributes.
• Age, City, Postal Code
• Composite Attributes
• Comprise of more than one attributes.
• Can be divided into smaller subparts, which represent more basic attributes
with independent meaning.
• Address consist of streetNumber, postalCode, city
Single valued & Multivalued Attributes
• Single Valued Attributes
• Can only have one value for the particular entity.
• Eg: A student can have only one student number
• Multivalued Attributes
• Attributes that can have many values.
• Eg: A student can have many certificate such as
• PMR, SPM, MLVK, etc.
Stored & Derived Attributes
• Stored Attributes
• The date_of_birth is the stored attribute.
• Derived attributes
• Can be computed from other attributes
• Example: age is derived from date_of_birth.
• Age is called derived attribute,
Null values
• In some cases, particular entity may not have an applicable value for
an attribute.
Cases:
• 1. The attribute value is missing.
• E.g.: Height attribute is NULL.
• 2. It is not known whether the attribute value exist.
• College degree – some people may have it and some not.
• Therefore, NULL value has to be created
Domain
• Set of possible values for an attribute.
• Each simple attribute of entity is associated with value set (domain of
values)
• It specify the sets value that may be assigned to that attribute for
each individual entity.
• Example given an attribute named GENDER, the domains are MALE
and FEMALE.
• Formally written as: GENDER = {MALE, FEMALE}
Degree
• The degree of relation is the number of attributes it contains.
• For example, Student has four attributes, or degree four.
Tuple
HERE OR THERE?
Cardinality
• The number of tuples(rows) its contains.
Relational Schema
• Named relation defined by a set of attribute and domain name pairs.
• Common convention:
• RelationName (attribute_1, attribute_2,…..,attribute_n)
• Example:
• Branch (branchNo, street, city, postcode)
Relational Database schema

• A sets of relation schema.


• The example shows the database schema for COMPANY =
• {EMPLOYEE, DEPARTMENT, DEPENDENT, PROJECT}
• Relation
DB Schema and Relation Schema
Relational Schema
Activity
• Create a database schema for a distributed grid management system
• Relations
• Attributes
• Tuples
• Values
• Diagrams to represent degree and cardinality
Relation Keys
• Refers to the important attribute in an entity.
• Determine the uniqueness of a row in given table.
• Identifiers for each rows.
• An attribute or more than one attributes can be a key
• Types of keys:
• Primary Key
• Candidate Key
• Alternate Key
• Foreign key
Primary Key
• Is an attributes that uniquely identify each row.
• Each table must have primary key.
• Cannot be NULL value to maintain Entity Integrity.
• Primary key is the one that officially declared as the row identifier inside a
specific table.
• Eg: studentID for Table Students
Candidate key
• A candidate key is a single field or the least combination of fields that
uniquely identifies each record in the table.
• There can be more than one candidate keys in a relation.
• Criteria for the candidate keys:
• It must contain unique values
• It must not contain null values
• It contains the minimum number of fields to ensure uniqueness
• It must uniquely identify each record in the table
Candidate Key
Alternate key
• An alternate key is any candidate key that is not primary key.
• Alternate keys are sometimes referred as secondary keys.
Foreign Key

• Attribute is an attributes whose value match the primary key


values in related tables. Creates a relationship between relations.
Summary of Relational Database Components
HERE OR THERE?
Activity
Relational Model Relationship
• An association between entities.
• Entities that participate in the relationship are called participants.
• Specifies how many instances of an entity relate to one instance of
another entity.
• Types:
• One to Many (1:M) Relationship
• Many to Many (m:N) Relationship
• Self Referencing Relationship
One to many (1:M)

• Table A may have many linked records in Table B


• But each record in Table B may have only one corresponding
record in Table A.
Many to many (m:N)
• Table A may have many linked records in Table B
• Table B may have many record corresponding record in Table A.
• M: N relationship is not a good choice in database.
• Normally when we have M:N relationship, we have to separate into
1:M relationship.
• A course can be taken by many students and the students can take as many
courses as they want.
Open Book Exercise
• A company has several departments. Each department has a
supervisor and at least one employee.
• Employees must be assigned to at least one department. Projects will
be given to the employee and it will be done in a group.
• At least one employee is assigned to one project or more. The
important data files are the names of the departments, projects,
supervisors and employees, as well as the supervisor and employee
number, department code and unique project number.
• Identify the entity.
• Identify the relationships.
Entity Relations Modeling
• Entity-Relationship Modeling (ERM) is a conceptual framework used
in database design to visually represent the data and its relationships
within a system. It provides a way to model the structure of a
database at a high level, making it easier to understand the data
requirements and how different entities interact with one another.
Creating ER Models
• Creating an Entity-Relationship (ER) model involves several steps that
help in identifying the entities, their attributes, and the relationships
between them
Identify the Purpose of the Model
• Define the Scope: Understand the system or application for which
you are creating the ER model. Determine what data needs to be
captured and how it will be used.
• Gather Requirements: Consult with stakeholders (users, business
analysts, etc.) to gather requirements and understand the data needs.
Identify Entities
• Define Entities: Identify the main objects or concepts that will be
represented in the database. An entity can be a person, place, object,
event, or concept.
• Examples: In a university database, entities might include Student,
Course, Instructor, and Department.
Identify Attributes
• Define Attributes: For each entity, identify the attributes that describe its
characteristics. Attributes provide more information about the entity.
• Types of Attributes:
• Simple Attributes: Indivisible (e.g., Name, Age).
• Composite Attributes: Can be divided into smaller parts (e.g., Address can be divided
into Street, City, State).
• Derived Attributes: Can be calculated from other attributes (e.g., Age from Date of
Birth).
• Multi-valued Attributes: Can have multiple values (e.g., Phone Numbers).
• Example: For the Student entity, attributes might include StudentID
(Primary Key), Name, Email, and DateOfBirth.
Identify Relationships
• Define Relationships: Determine how the entities are related to one
another. Identify the nature of the relationships (one-to-one, one-to-
many, many-to-many).
• Examples:
• A Student can enroll in multiple Courses (Many-to-Many).
• An Instructor teaches multiple Courses (One-to-Many).
• Relationship Names: Assign meaningful names to relationships (e.g.,
"Enrolls," "Teaches").
Determine Cardinality and Participation
• Cardinality: Specify the cardinality of each relationship, indicating
how many instances of one entity can be associated with instances of
another entity.
• One-to-One (1:1): Each instance of Entity A is related to one instance of Entity
B.
• One-to-Many (1:N): Each instance of Entity A can be related to multiple
instances of Entity B.
• Many-to-Many (M:N): Instances of Entity A can be related to multiple
instances of Entity B and vice versa.
• Participation: Determine whether the participation of an entity in a
relationship is mandatory or optional.
Create the ER Diagram
• Visual Representation: Use a diagramming tool (such as Dia,
Lucidchart, Draw.io, or Microsoft Visio) or pen and paper to create
the ER diagram.
• Symbols:
• Rectangles for entities.
• Ovals for attributes.
• Diamonds for relationships.
• Lines connecting entities to their attributes and relationships.
• Example Diagram: The ER diagram for the university database might
show the Student and Course entities, their attributes, and the
relationship "Enrolls" connecting them.
Convert to Database Schema
• Implementation: Once the ER model is finalized, it can be converted
into a database schema. This involves creating tables, defining
primary and foreign keys, and establishing constraints based on the
ER model
Examples of ER Diagram
HERE OR THERE?
To Be Continued

Questions
Comments

You might also like