Sie sind auf Seite 1von 47

LECTURE No:3

CSC271 Database Systems

Modeling Data in the Organization

Dr. Khalid Latif


Objectives
n Introduction to data modeling
n Write good names and definitions for entities,
relationships, and attributes.
n Distinguish unary, binary, and ternary relationships
n Model different types of attributes, entities, relationships,
and cardinalities
n Draw E-R diagrams for common business situations
n Convert many-to-many relationships to associative
entities
n Model time-dependent data using time stamps

2
Need of an Open Model
n How to represent a database schema?
n SQL? Non standard DBMS syntax!
n The model must be as open as possible
and not tied to any technology (e.g. a
DBMS) or to any particular business
methodology (of any organization).
n Entity-Relational Model introduced in 1976
by Peter Chen.

3
Entity-Relational Model
n E-R Model is a detailed, logical representation
of the data for an organization or for a
business area.
n It mainly answers following questions:
n What are the entities and relationships in
the enterprise?
n What information about these entities and
their relationships should we store in the
database?
n What are the integrity constraints or
business rules that hold?
4
E-R Model Constructs
n The
E-R model is usually expressed as
an E-R diagram.
n Entities
(tables), Attributes (columns),
Relationships (links)
n Widespread CASE tool-support
n Chen vs. Martin notations
n Crows Foot or fork notation

5
En##es Instances and Types
n Entity instance: A person, place, object,
event, or concept in the user environment
about which the organization wishes to
maintain data.
n A single occurrence of an entity type,
corresponding to a row in a table.
n Entity Type collection of entities, often
corresponds to a table.

Player Match Team Ground

6
Entity Type Characteristics
n Good
n Have many instances in the database (e.g.
products)
n Composed of multiple attributes (product id,
name, price, expiry)
n Bad
n Singleton (entities with just one instance)
n An
individual application user, single organization,
output of the application (e.g. a sales report)
n Naming Conventions:
n Singular (e.g. Player) vs. Plural (e.g. Players)
7
Next: Attributes and then
Relationships

8
Attributes
n Attributeproperty or characteristic of an
entity or relationship type.
n Examples: Product name (text), Barcode
(numeric), Product price (numeric), Expiry
date (date/time)
Career Runs
Player
Player Name Centuries
Player Name
Career Runs
Player Centuries
9
Common Attribute Data Types
n Integer, smallint, tinyint: A finite subset
of the integers that is machine-dependent.
n Float (n). Floating point number, with
user-specified precision of at least n digits.
n Date, datetime, time, year: Different date
and time values
n Char (n): Fixed n length character string.

n Varchar (n): Variable length character


strings, with user-specified maximum n.
10
Check Point
n Differentiate between entity, instance,
attribute, and data value.

n Name, Player, Furniture, Fatima, 35


n Painting, Height, Park Road, Watt

n Imperial College, 14 Aug 1947

n Painting of Mona Lisa

11
Attribute Classification
n Simple n Composite
n Price n Address (street, city)
n Single-Valued n Multivalued
n Customer Age n Phone number
n Stored n Derived
n Product Price n Order amount
n Required n Optional
n Barcode n Expiry date

... and Identifiers


12
Lets discuss these in detail

13
Derived Attributes
n Value can be computed from other attributes
n Example: Age (given a Date of Birth)

Player

Player Name
Career Runs
Centuries
[Average]

14
Composite Attributes
n An attribute broken into many parts
n Compound data values

Player

Player Name (First, Last)


Career Runs
Centuries

15
Multi-valued Attributes
n Multiple data values for one attribute are
allowed
n Multi-valued and composite!

Player Player

Player Name Player Name


Career Runs Career Runs
Centuries Centuries
{Affiliation} {Affiliation (TeamName, Span (From, To))}

16
Time-stamping Example
n Use attribute that is both multivalued and
composite to maintain history as well as a
time reference.

17
Identifier (Key)
n Identifier (Key)An attribute (or
combination of attributes) that uniquely
identifies individual entity instances.

n Examples
n Employees CNIC
n Products Barcode
n Travellers Passport number

18
Simple and Composite Identifiers
The identifier is boldfaced and underlined

19
Characteristics of Identifiers
n Will not be null or empty.
n Will not change in value over time.
n No intelligent identifiers e.g., containing
campus or degree-program of student that
might change (F12ISCS101).
n Substitute
new, simple keys for long,
composite keys

20
Entity and Attributes Combined
n Entity example with a multivalued
attribute (Skill) as well as a derived
attribute (Years_Employed)

Derived
Multivalued
from date
an employee can
employed and
have more than
current date
one skill

21
Choosing Entity and Attribute Names
n Price vs. price_float
n Related to business, not technical, characteristics
n $@l35 for Sales
n Readable and Repeatable
n Prc?
n Meaningful and self-documenting
n Price vs. Amount
n Unique in meaning, in contrast to confusing terms
n A, S, et.
n Composed of words from an approved list
22
Check Point
n HEC is streamlining their scholarship unit
and need your help to implement a
database system
n Scholarships are granted by a source entity
(e.g. EU, WorldBank, IDB, GoP); Each
entity may announce multiple scholarship
programs; An applicant, any Pakistani
national may apply for multiple scholarships
n Target: Identify entities and attributes

23
Some of the entities

24
Canteen and Stores
 

 
 

   -


   
   
     


 
   
   


   


  
  

   






  + ,

 
+ ,



   
    #(') 
#

   
!   #
#


  
  "
  
$#%& '' 


(')  
   

(')  -
+ ,
 
#


+ ,&, *

#

#
 #(') 
#(')  

(') 
25
Relationships
n Relationship instance is modeled as
lines between specific entity instances

Player Team
Inzimam-ul-Haq Pakistan
Brian Lara Lahore Badshah
Rana Naveed West Indies

26
Relationships
n Relationship Type: Association between
entity types.
n Modeled as labeled line between entity
types
Plays For
Player Team

27
Cardinality of Relationships
n Cardinality Constraints - the number of
instances of one entity that can or must be
associated with each instance of another
entity
n Minimum Cardinality
n Zero - optional
n One - mandatory

n Maximum Cardinality
n The maximum number of entity instances that
could be association with the target entity in the
relationship

28
One-to-One Association
n Each entity in the relationship will have exactly
one related entity instance
n Example: Employee-ParkingSpace

manages
Manager Team

A manager is associated A team is optionally managed


with only one team at most by one manager at most.
Min: One team Min: No manager
Max: One team Max: One manager

29
One-to-Many Association
n An entity instance on one side of the relationship
can have many related entity instances, but an
entity on the other side will have a maximum of
one related entity instance.

A student is enrolled A degree may have


in one and only one recorded no or many
degree enrolled students

30
Many-to-Many Association
n Entities on both sides of the relationship can
have many related entities on the other side
n Example: Student-Course

A project must be An employee can be


assigned to at least one assigned to any number
employee, and may be of projects, or may not
assigned to many be assigned to any at all

31
Degree of Relationships
n Degree of a relationship is the number of
entity types that participate in it.
n Unary: One entity related to another of
the same entity type
One-to-one a persons marries One-to-many many players are
with just one other person lead by one player (a captain)
married To leads

Person Player
32
Binary Relationships
n Entities of two different types related to
each other
1-1 manages
n
Manager Team

1-M
played By
n Match Player

play for
n M-M Player Team
33
Ternary Relationship
n Entities of three different types related to
each other
Match

Parts
Team Plays At Ground

Vendor supplies Warehouse

34
Multiple Relationships
n Entities can have more than one type of
relationship between them.

35
Relationship with Attributes
n Relationships can have attributes of
their own
n These describe features pertaining to
the association between the entities
in the relationship

36
Binary Relationship with Attributes
n Here, the date completed attribute
pertains specifically to the employees
completion of a course
n Hence an attribute of the relationship

37
Ternary Relationship with
Attributes
n Shipping and cost is associated with the
existence of the relationship.

Shipping_mode
Unit_Cost

38
What to do with attributes of
a relationship in a database?

Transform to an entity
-> Hence a table

39
Associative Entities
n A many-to-many relationship (with/out
attributes) is converted into an entity.
n Ternary relationships should also be converted to
associative entities.
n The associative entity preferably has a unique
identifier (mostly composite) and may also have
other attributes.
n The associative entity may participate in other
relationships other than the entities of the
associated relationship.

40
Associative Entity Example
n Many-to-many cardinality between entities has
been replaced by two one-to-many relationships
with the associative entity.

41
Bill of Materials Structure
n Unary M-M association with attributes

42
Ternary Relationship as an
Associative Entity

43
Strong vs. Weak Entities
Strong Entities Weak Entity
n Identifier underlined n Identifier underlined with
with a dashed line a strong double line
n Has its own unique n Only has partial identifier
identifier n Dependent on a strong
n Exist independently of entity (identifying
other types of entities owner), cannot exist on
n Identifying relationship its own
links strong entities to n Entity box has double line
weak entities

44
Identifying Relationship

Strong entity Weak entity

45
Summary of E-R Notations
Entity
Attribute
symbols
symbols

A special entity
that is also a Relationship
relationship symbols

Relationship
degrees specify
number of
entity types Relationship
involved cardinalities
specify how
many of each
entity type is
allowed46
Microsoft Visio
Notation for Pine
Valley Furniture
E-R diagram

Other modeling
software tools
may have
different notation
for the same
constructs.

47

Das könnte Ihnen auch gefallen