0% found this document useful (0 votes)
28 views33 pages

Chapter 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 33

Data Models

Create an ER diagram based on the following


scenario:
A company is organized into DEPARTMENTs. Each
department has a name, number and an employee
who manages the department Each department
Controls a number of PROJECTs. Each project has a
unique name, unique number and location. An
EMPLOYEE has an ID number, address, salary and
sex. Each employee works for one department but
may work on several projects.
Objectives

• Describe the types of data models


• Create an entity-relationship model
• List the types of relationships between entities
• Define a Relational Database Management System (RDBMS)
• Describe the operators that work on relations
Data Models

• A data model is a description of the organization of data in a


database.
• defines the logical design of data.
• describes the relationship among data.
• Describes any constraints that have to be defined on the data.
• Categories:
• Object-based logical model – focuses on describing the data,
the relationship among the data, and any constraints
defined.
• Record-based logical model – focuses on describing the data
structure and the access techniques in a Database
Management System.
Object-based logical model

• most widely used is the entity-relationship model (E/R model) .

• accepted as the ideal data model for database design


• Introduced by Peter Chen in 1976

Data Models
Entity-Relationship Model

• is based on a real-world perception that comprises;


• a collection of objects or entities
• the relationships among entities
• diagram used to represent an E/R model is called an E/R diagram.
• E/R diagram illustrate the logical structure of databases
• components of an E/R diagram:
• Entities
• Relationships
• Attributes

Data Models
Entity-Relationship Model (Contd..)

Chen Notation - Symbol


Rectangle represents an Entity

Diamond represents a Relationship

Oval represents Attribute

1 M Lines with labels represents Cardinality


Entity-Relationship Model (Contd..)
Sample ER-Diagram

Attribute Attribute Attribute

Line label
Entity Relationship Entity Attribute

Attribute
relationship

Attribute Entity Attribute


Entity-Relationship Model (Contd..)

Sample E/R Diagram


Entity-Relationship Model (Contd..)

Entities

• An entity is any object, place, person, or activity about which


data is recorded.
• are named and represented inside a box.
• two types of entities:
• Dependent
• Independent
• Dependent entities are also called weak entities, and
independent entities are called regular entities.
• Weak entities are represented by double-lined boxes.

Data Models
Entity-Relationship Model (Contd..)

Dependent Entity

Data Models
Entity-Relationship Model (Contd..)

Relationships
• A relationship is an association among entities.
• depicted as a diamond with the name of the relationship type.

Data Models
Entity-Relationship Model (Contd..)

Relationships
• A relationship can associate an entity with itself.
• Multiple relationships can also exist between the same entities.

Data Models
Entity-Relationship Model (Contd..)

Relationships
• There are three types of relationships:
• One-to-One
• One-to-Many (or Many-to-One)
• Many-to-Many

One-to-One Relationship
Entity-Relationship Model (Contd..)

Relationships

Many-to-One Relationship

Many-to-Many Relationship
Entity-Relationship Model (Contd..)

Attributes
• An attribute is a property of an entity.
• Attributes are depicted as ellipses, labeled with the name of
the property. The key properties are underlined.
• A relationship can also have attributes.
Entity-Relationship Model (Contd..)

Attributes
Entity-Relationship Model (Contd..)
Subtypes and Supertypes
• A subtype is a subset of another entity.
Entity-Relationship Model (Contd..)
Subtypes and Supertypes
• A subentity/subtype always depends on the supertype.
• attributes of a supertype apply to all of its subtypes.
• Subtypes are connected to the supertype by an unnamed
relationship.
• Supertype is connected to the relationship with a line
containing a crossbar.
Activity
Record-based Models

Three types of record-based models:

1. Hierarchical model
• data is represented in the form of a tree
2. Network model
• Similar to a hierarchical model in the way that data and the
relationships are represented in the form of records and
links.
3. Relational model
• database is structured in fixed-format records of several
types.
Record-based Models

Three types of record-based models:

1. Hierarchical model
• data is represented in the form of a tree
2. Network model
• Similar to a hierarchical model in the way that data and the
relationships are represented in the form of records and
links.
3. Relational model
• database is structured in fixed-format records of several
types.
Record-based Models

Three types of record-based models:

1. Hierarchical model
• data is represented in the form of a tree
2. Network model
• Similar to a hierarchical model in the way that data and the
relationships are represented in the form of records and
links.
3. Relational model
• database is structured in fixed-format records of several
types.
Record-based Models

1. Hierarchical model
Record-based Models

2. Network model
Record-based Models

3. Relational Model

• Dr. E. F. Codd first described the relational model in 1970.


• to simplify the database structure.
• represents data in the database as simple tables in the row-
column format.
• A RDBMS can be defined as a DBMS where all data visible to the
user is organized strictly as tables of data values, and where all
database operations work on these tables.
Record-based Models

Relational Model
Relational Data Structure

• A table is called a relation, the row (or record) in the table is


called a tuple, and the column (or field) is called an attribute.
• The number of tuples is called the cardinality of the table, and
the number of attributes is called the degree of the table.
• A table where every row is different from all other rows is called
a relation in mathematical terms.
• One important property of a relation is that its rows are
unordered.
• Every table must have some column or combination of columns
that uniquely identifies each row in the table. This column (or
columns) is called the primary key of the table.

Data Models
Relational Data Structure (Contd..)

• In an RDBMS, missing or unknown information is represented


as a NULL value in a table.
• Relationships are represented by common data values stored
in two or more tables.
• A column in one table whose value matches the primary key in
some other table is called a foreign key.
• Together, a primary key and a foreign key create a parent-child
relationship between the tables that connect them.

Data Models
Relational Algebra

• Relational algebra is a collection of operators that operate on


relations.
• The operators used in relational algebra are:
• Restrict
• Project
• Product
• Union
• Intersect
• Difference
• Join
• Divide
Data Models
Summary

• Data models can be classified as:


• Object-based logical models
• Record-based logical models
• The entity-relationship model is based on a real-world perception
that comprises a collection of objects or entities and the
relationships among these.
• An entity is any object, place, person, or activity about which data
is recorded.
• A relationship is an association among entities.
• An attribute is a property of a given entity.
Summary (Contd..)

• In the entity-relationship diagramming technique:


• Entities are represented as boxes.
• Relationships are represented as diamonds.
• Attributes are represented as ellipses.
• In the relational model, data is represented in tables
(relations) of rows (tuples) and columns (attributes).
• The number of tuples is called the cardinality of the table, and
the number of attributes is called the degree of the table.
• A column (or columns) that uniquely identifies each row in the
table is called the primary key of the table.
• Relationships are represented by common data values stored
in two or more tables.
Data Models
Summary (Contd..)

• A column in one table whose value matches the primary key in


some other table is called a foreign key.
• The eight operators that operate on relations are restrict,
project, product, union, intersect, difference, join, and divide.

Data Models

You might also like