Chap5of SDBMS

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

Spatial database Management system

Lecture 05: Conceptual Modeling using the Entity-


Relationship Model
Conceptual Modeling using the Entity-Relationship Model

•Contents
• Basic concepts: entities and entity types, attributes and keys, relationships and relationship
types
• Entity-Relationship schema (ER diagram)
• Constraints on relationship types
• Design choices
• Enhanced Entity-Relationship model features
• Steps in designing an ER schema
• Translation of an ER schema to tables
Cont…

•What does Conceptual Design include?

• Entity-Relationship model is used in the conceptual design of a database (+


conceptual level, conceptual schema)
• Design is independent of all physical considerations (DBMS, OS, . . . ).
• Questions that are addressed during conceptual design:
• What are the entities and relationships of interest ?
• What information about entities and relationships among entities needs to be stored in the
database?
• What are the constraints (or business rules) that ( must ) hold for the entities and
relationships?
• A database schema in the ER model can be represented pictorially
• (Entity-Relationship diagram)
Cont…
•Basic Terms: Entity Types, Entity Sets, Attributes and Keys

• Entity: real-world object or thing with an independent existence and which is


distinguishable from other objects. Examples are a person, car, customer, product,
gene, book etc.
• Attributes: an entity is represented by a set of attributes (its descriptive properties),
e.g., name, age, salary, price etc. Attribute values that describe each entity become a
major part of the data eventually stored in a database.
• With each attribute a domain is associated, i.e., a set of permitted values for an
attribute. Possible domains are integer, string, date, etc.
• Entity Type: Collection of entities that all have the same attributes, e.g., persons, cars,
customers etc.
• Entity Set: Collection of entities of a particular entity type at any point in time; entity
set is typically referred to using the same name as entity type.
Cont…
•Key attributes of an Entity Type

• Entities of an entity type need to be distinguishable.


• A superkey of an entity type is a set of one or more attributes whose values
uniquely determine each entity in an entity set.
• A candidate key of an entity type is a minimal (in terms of number of attributes)
superkey.
• For an entity type, several candidate keys may exist. During conceptual design,
one of the candidate keys is selected to be the primary key of the entity type.
Cont…

•Relationships, Relationship Types, and Relationship Sets

• Relationship (instance): association among two or more entities, e.g.,


“customer ’Smith’ orders product ’PC42’ ”
• Degree of a relationship: refers to the number of entity types that participate in
the relationship type (binary, ternary, . . . ).
• Roles: The same entity type can participate more than once in a relationship type.
Role labels clarify semantics of a relationship, i.e., the way in which an entity
participates in a relationship.
• Relationship Attributes: A relationship type can have attributes describing
properties of a relationship.
Cont…

“customer ’Smith’ ordered product ’PC42’ on January 11 , 2005, for $2345”.


• These are attributes that cannot be associated with participating entities only, i.e.,
they make only sense in the context of a relationship.
• Note that a relationship does not have key attributes! The identification of a
particular relationship in a relationship set occurs through the keys of participating
entities.
Cont…
•Example of an Entity-Relationship Diagram

FName LName CAddress Prodname

Account CUSTOMERS PRODUCTS

orders

Quantity offers Price

SUPPLIERS Chain

SName SAddress

Customers-Suppliers-Products Entity-Relationship Diagram


Cont…
• Rectangles represent entity types
• Ellipses represent attributes
• Diamonds represent relationship types
• Lines link attributes to entity types and entity types to relationship types
• Primary key attributes are underlined
• Empty Circle at the end of a line linking an attribute to an entity type represents
an optional (null) attribute ( not mentioned in textbook)
• Not in the above diagram, but later in examples:
• Double Ellipses represent multi-valued attributes
Cont…
•Constraints on Relationship Types

• Limit the number of possible combinations of entities that may participate in a relationship set.
There are two types of constraints: cardinality ratio and participation constraints
• Very useful concept in describing binary relationship types. For binary relationships, the
cardinality ratio must be one of the following types:
• Many-To-Many ( default )

EMPLOYEES DEPARTMENTS

• Meaning: An employee can work in many departments (≥ 0) , and a department can have several
employees
Cont…

• Many-To-One

EMPLOYEES DEPARTMENTS

• Meaning: An employee can work in at most one department (≤ 1), and a department can have
several employees.
• One-To-Many
EMPLOYEES DEPARTMENTS

• Meaning: An employee can work in many departments (≥ 0) , but a department can have at most
one employee.
• One-To-One
EMPLOYEES DEPARTMENTS

• Meaning: An employee can work in at most one department, and a department can have at most
one employee.
Cont…
• Steps in Designing an Entity-Relationship Schema
• Step 1: Identify entity types (entity type vs. attribute)
• Step 2: Identify relationship types
• Step 3: Identify and associate attributes with entity and relationship types
• Step 4: Determine attribute domains
• Step 5: Determine primary key attributes for entity types
• Step 6: Associate (refined) cardinality ratio(s) with relationship types
• Step 7: Design generalization/specialization hierarchies including constraints
(includes natural language statements as well)
Cont…

•Translation of ER Schema into Tables

• An ER schema can be represented by a collection of tables which represent


contents of the database ( instance ).
• Primary keys allow entity types and relationship types to be expressed uniformly
as tables.
• For each entity and relationship type, a unique table can be derived which is
assigned the name of the corresponding entity or relationship type.
• Each table has a number of columns that correspond to the attributes and which
have unique names. An attribute of a table has the same domain as the attribute in
the ER schema.
• Translating an ER schema into a collection of tables is the basis for deriving a
relational database schema from an ER diagram.
Cont…
• Translation of the entity type CUSTOMERS into table
CUSTOMERS

In SQL:
create table Customers(
FName char(40),
LName char(40),
CAddress char(70),
Account real
);
A row in such a table corresponds to an entity from the entity set.
Logical Data Model: The Relational Model

• Relational model is based on set theory


• Main concepts
• Domain: a set of values for a simple attribute
• Relation: cross-product of a set of domains
• Represents a table, i.e. homogeneous collection of rows (tuples)
• The set of columns (i.e. attributes) are same for each row
• Comparison to concepts in conceptual data model
• Relations are similar to but not identical to entities
• Domains are similar to attributes
Relational Schema
• Schema of a Relation
• Enumerates columns, identifies primary key and foreign keys.
• Primary Key :
• one or more attributes uniquely identify each row within a table
• Foreign keys
• R’s attributes which form primary key of another relation S
• Value of a foreign key in any tuple of R match values in some row of S
• Relational schema of a database
• collection of schemas of all relations in the database
• Example: Figure (next slide)
• Ablue print summary drawing of the database table structures
• Allows analysis of storage costs, data redundancy, querying capabilities
• Some databases were designed as relational schema in 1980s
• Nowadays, databases are designed as E R models and relational schema is generated via CASE tools
Relational Schema for “Point”, “Line”, “Polygon” and “Elevation”

• Relational model restricts attribute domains


• simple atomic values, e.g. a number
• Disallows complex values (e.g. polygons) for columns
• Complex values need to be decomposed into simpler domains
• A polygon may be decomposed into edges and vertices
More on Relational Model
• Integrity Constraints
• Key: Every relation has a primary key.
• Entity Integrity: Value of primary key in a row is never undefined
• Referential Integrity: Value of an attribute of a Foreign Key must appear as a value in the
primary key of another relationship or must be null.

• Normal Forms (NF) for Relational schema


• Reduce data redundancy and facilitate querying
• 1st NF: Each column in a relation contains an atomic value.
• 2nd and 3rd NF: Values of non-key attributes are fully determined by the values of the
primary key, only the primary key, and nothing but the primary key.
• Other normal forms exists but are seldom used
• Translating a well-designed ER model yields a relational schema in 3rd NF
• satisfying definition of 1st, 2nd and 3rd normal forms
Extending ER with Spatial Concepts
•Motivation
•ER Model is based on discrete sets with no implicit relationships
•Spatial data comes from a continuous set with implicit relationships
•Any pair of spatial entities has relationships like distance, direction, …
•Explicitly drawing all spatial relationship
•clutters ER diagram
•generates additional tables in relational schema
•Misses implicit constraints in spatial relationships (e.g. partition)
•Pictograms
•Label spatial entities along with their spatial data types
•Allows inference of spatial relationships and constraints
•Reduces clutter in ER diagram and relational schema
ER Diagram with Pictograms: An Example

You might also like