DATABASE SYSTEMS UNIT 4 - PowerPoint PPT Presentation

About This Presentation
Title:

DATABASE SYSTEMS UNIT 4

Description:

UNIT 4 – PowerPoint PPT presentation

Number of Views:3
Slides: 96
Provided by: seetha8390
Category:

less

Transcript and Presenter's Notes

Title: DATABASE SYSTEMS UNIT 4


1
UNIT 4 Other Relational Languages
BY Ms D. SEETHALAKSHMI ASSISTANT PROFESSOR BON
SECOURS COLLEGE FOR WOMEN THANJAVUR
2
Other Relational Languages
  • Tuple Relational Calculus
  • Domain Relational Calculus
  • Query-by-Example (QBE)

3
Tuple Relational Calculus
  • A nonprocedural query language, where each query
    is of the form
  • t P (t )
  • It is the set of all tuples t such that predicate
    P is true for t
  • t is a tuple variable, t A denotes the value
    of tuple t on attribute A
  • t ? r denotes that tuple t is in relation r
  • P is a formula similar to that of the predicate
    calculus

4
Predicate Calculus Formula
  • 1. Set of attributes and constants
  • 2. Set of comparison operators (e.g., ?, ?, ?,
    ?, ?, ?)
  • 3. Set of connectives and (?), or (v) not (?)
  • 4. Implication (?) x ? y, if x if true, then y
    is true
  • x ? y ???x v y
  • 5. Set of quantifiers
  • ??t ??r (Q (t )) ??there exists a tuple in t in
    relation r such that
    predicate Q (t ) is true
  • ?t ??r (Q (t )) ??Q is true for all tuples t in
    relation r

5
Banking Example
  • branch (branch_name, branch_city, assets )
  • customer (customer_name, customer_street,
    customer_city )
  • account (account_number, branch_name, balance )
  • loan (loan_number, branch_name, amount )
  • depositor (customer_name, account_number )
  • borrower (customer_name, loan_number )

6
Example Queries
  • Find the loan_number, branch_name, and amount for
    loans of over 1200

t t ? loan ? t amount ? 1200
  • Find the loan number for each loan of an amount
    greater than 1200
  • t ? s ??loan (t loan_number s
    loan_number ? s amount ? 1200)
  • Notice that a relation on schema
    loan_number is implicitly defined by
  • the query

7
Example Queries
  • Find the names of all customers having a loan, an
    account, or both at the bank

t ?s ? borrower ( t customer_name s
customer_name ) ? ?u ? depositor ( t
customer_name u customer_name )
  • Find the names of all customers who have a
    loan and an account at the bank

t ?s ? borrower ( t customer_name s
customer_name ) ? ?u ? depositor ( t
customer_name u customer_name )
8
Example Queries
  • Find the names of all customers having a loan at
    the Perryridge branch

t ?s ? borrower (t customer_name s
customer_name ? ?u ? loan (u
branch_name Perryridge
? u loan_number s loan_number ))
  • Find the names of all customers who have a loan
    at the Perryridge branch, but no account at
    any branch of the bank

t ?s ? borrower (t customer_name s
customer_name ? ?u ? loan (u
branch_name Perryridge
? u loan_number s loan_number ))
? not ?v ? depositor (v customer_name

t customer_name )
9
Example Queries
  • Find the names of all customers having a loan
    from the Perryridge branch, and the cities in
    which they live

t ?s ? loan (s branch_name Perryridge
? ?u ? borrower (u loan_number s
loan_number ? t customer_name u
customer_name ) ? ? v ? customer (u
customer_name v customer_name
? t customer_city v
customer_city )))
10
Example Queries
  • Find the names of all customers who have an
    account at all branches located in Brooklyn

t ? r ? customer (t customer_name r
customer_name ) ? ( ? u ? branch (u
branch_city Brooklyn ? ? s ?
depositor (t customer_name s customer_name
? ? w ? account ( waccount_number
s account_number ? ( w
branch_name u branch_name ))))
11
Safety of Expressions
  • It is possible to write tuple calculus
    expressions that generate infinite relations.
  • For example, t ? t?? r results in an
    infinite relation if the domain of any attribute
    of relation r is infinite
  • To guard against the problem, we restrict the set
    of allowable expressions to safe expressions.
  • An expression t P (t ) in the tuple
    relational calculus is safe if every component of
    t appears in one of the relations, tuples, or
    constants that appear in P
  • NOTE this is more than just a syntax condition.
  • E.g. t t A 5 ? true is not safe --- it
    defines an infinite set with attribute values
    that do not appear in any relation or tuples or
    constants in P.

12
Domain Relational Calculus
  • A nonprocedural query language equivalent in
    power to the tuple relational calculus
  • Each query is an expression of the form
  • ? x1, x2, , xn ? P (x1, x2, , xn)
  • x1, x2, , xn represent domain variables
  • P represents a formula similar to that of the
    predicate calculus

13
Example Queries
  • Find the loan_number, branch_name, and amount
    for loans of over 1200

? l, b, a ? ? l, b, a ? ? loan ? a gt 1200
  • Find the names of all customers who have a loan
    of over 1200

? c ? ? l, b, a (? c, l ? ? borrower ? ? l,
b, a ? ? loan ? a gt 1200)
  • Find the names of all customers who have a loan
    from the Perryridge branch and the loan amount
  • ? c, a ? ? l (? c, l ? ? borrower ? ?b (? l,
    b, a ? ? loan ?

  • b Perryridge))
  • ? c, a ? ? l (? c, l ? ? borrower ? ? l,
    Perryridge, a ? ? loan)


14
Example Queries
  • Find the names of all customers having a loan, an
    account, or both at the Perryridge branch

? c ? ? l ( ? c, l ? ? borrower
? ? b,a (? l, b, a ? ? loan ? b
Perryridge)) ? ? a (? c, a ? ?
depositor ? ? b,n (? a, b, n ? ?
account ? b Perryridge))
  • Find the names of all customers who have an
    account at all branches located in Brooklyn

? c ? ? s,n (? c, s, n ? ? customer) ?
? x,y,z (? x, y, z ? ? branch ? y
Brooklyn) ? ? a,b (? x, y, z ?
? account ? ? c,a ? ? depositor)
15
Safety of Expressions
  • The expression
  • ? x1, x2, , xn ? P (x1, x2, , xn )
  • is safe if all of the following hold
  • All values that appear in tuples of the
    expression are values from dom (P ) (that is,
    the values appear either in P or in a tuple of a
    relation mentioned in P ).
  • For every there exists subformula of the form ?
    x (P1(x )), the subformula is true if and only
    if there is a value of x in dom (P1) such that
    P1(x ) is true.
  • For every for all subformula of the form ?x (P1
    (x )), the subformula is true if and only if P1(x
    ) is true for all values x from dom (P1).

16
Query-by-Example (QBE)
  • Basic Structure
  • Queries on One Relation
  • Queries on Several Relations
  • The Condition Box
  • The Result Relation
  • Ordering the Display of Tuples
  • Aggregate Operations
  • Modification of the Database

17
QBE Basic Structure
  • A graphical query language which is based
    (roughly) on the domain relational calculus
  • Two dimensional syntax system creates templates
    of relations that are requested by users
  • Queries are expressed by example

18
QBE Skeleton Tables for the Bank Example
19
QBE Skeleton Tables (Cont.)
20
Queries on One Relation
  • Find all loan numbers at the Perryridge branch.
  • _x is a variable (optional can be omitted in
    above query)
  • P. means print (display)
  • duplicates are removed by default
  • To retain duplicates use P.ALL

21
Queries on One Relation (Cont.)
  • Display full details of all loans
  • Method 1

P._y
P._z
P._x
  • Method 2 Shorthand notation

22
Queries on One Relation (Cont.)
  • Find the loan number of all loans with a loan
    amount of more than 700
  • Find names of all branches that are not located
    in Brooklyn

23
Queries on One Relation (Cont.)
  • Find the loan numbers of all loans made jointly
    to Smith and Jones.
  • Find all customers who live in the same city as
    Jones

24
Queries on Several Relations
  • Find the names of all customers who have a loan
    from the Perryridge branch.

25
Queries on Several Relations (Cont.)
  • Find the names of all customers who have both an
    account and a loan at the bank.

26
Negation in QBE
  • Find the names of all customers who have an
    account at the bank, but do not have a loan from
    the bank.

means there does not exist
27
Negation in QBE (Cont.)
  • Find all customers who have at least two accounts.

means not equal to
28
The Condition Box
  • Allows the expression of constraints on domain
    variables that are either inconvenient or
    impossible to express within the skeleton tables.
  • Complex conditions can be used in condition boxes
  • Example Find the loan numbers of all loans made
    to Smith, to Jones, or to both jointly

29
Condition Box (Cont.)
  • QBE supports an interesting syntax for expressing
    alternative values

30
Condition Box (Cont.)
  • Find all account numbers with a balance greater
    than 1,300 and less than 1,500
  • Find all account numbers with a balance greater
    than 1,300 and less than 2,000 but not exactly
    1,500.

31
Condition Box (Cont.)
  • Find all branches that have assets greater than
    those of at least one branch located in Brooklyn

32
The Result Relation
  • Find the customer_name, account_number, and
    balance for all customers who have an account at
    the Perryridge branch.
  • We need to
  • Join depositor and account.
  • Project customer_name, account_number and
    balance.
  • To accomplish this we
  • Create a skeleton table, called result, with
    attributes customer_name, account_number, and
    balance.
  • Write the query.

33
The Result Relation (Cont.)
  • The resulting query is

34
Ordering the Display of Tuples
  • AO ascending order DO descending order.
  • Example list in ascending alphabetical order all
    customers who have an account at the bank
  • When sorting on multiple attributes, the sorting
    order is specified by including with each sort
    operator (AO or DO) an integer surrounded by
    parentheses.
  • Example List all account numbers at the
    Perryridge branch in ascending alphabetic order
    with their respective account balances in
    descending order.

35
Aggregate Operations
  • The aggregate operators are AVG, MAX, MIN, SUM,
    and CNT
  • The above operators must be postfixed with ALL
    (e.g., SUM.ALL. or AVG.ALL._x) to ensure that
    duplicates are not eliminated.
  • Example Find the total balance of all the
    accounts maintained at the Perryridge branch.

36
Aggregate Operations (Cont.)
  • UNQ is used to specify that we want to eliminate
    duplicates
  • Find the total number of customers having an
    account at the bank.

37
Query Examples
  • Find the average balance at each branch.
  • The G in P.G is analogous to SQLs group by
    construct
  • The ALL in the P.AVG.ALL entry in the balance
    column ensures that all balances are considered
  • To find the average account balance at only those
    branches where the average account balance is
    more than 1,200, we simply add the condition
    box

38
Query Example
  • Find all customers who have an account at all
    branches located in Brooklyn.
  • Approach for each customer, find the number of
    branches in Brooklyn at which they have accounts,
    and compare with total number of branches in
    Brooklyn
  • QBE does not provide subquery functionality, so
    both above tasks have to be combined in a single
    query.
  • Can be done for this query, but there are queries
    that require subqueries and cannot always be
    expressed in QBE.
  • In the query on the next page
  • CNT.UNQ.ALL._w specifies the number of distinct
    branches in Brooklyn. Note The variable _w is
    not connected to other variables in the query
  • CNT.UNQ.ALL._z specifies the number of distinct
    branches in Brooklyn at which customer x has an
    account.

39
Query Example (Cont.)
40
Modification of the Database Deletion
  • Deletion of tuples from a relation is expressed
    by use of a D. command. In the case where we
    delete information in only some of the columns,
    null values, specified by , are inserted.
  • Delete customer Smith
  • Delete the branch_city value of the branch whose
    name is Perryridge.

41
Deletion Query Examples
  • Delete all loans with a loan amount greater than
    1300 and less than 1500.
  • For consistency, we have to delete information
    from loan and borrower tables

42
Deletion Query Examples (Cont.)
  • Delete all accounts at branches located in
    Brooklyn.

43
Modification of the Database Insertion
  • Insertion is done by placing the I. operator in
    the query expression.
  • Insert the fact that account A-9732 at the
    Perryridge branch has a balance of 700.

44
Modification of the Database Insertion (Cont.)
  • Provide as a gift for all loan customers of the
    Perryridge branch, a new 200 savings account for
    every loan account they have, with the loan
    number serving as the account number for the new
    savings account.

45
Modification of the Database Updates
  • Use the U. operator to change a value in a tuple
    without changing all values in the tuple. QBE
    does not allow users to update the primary key
    fields.
  • Update the asset value of the Perryridge branch
    to 10,000,000.
  • Increase all balances by 5 percent.

46
Microsoft Access QBE
  • Microsoft Access supports a variant of QBE called
    Graphical Query By Example (GQBE)
  • GQBE differs from QBE in the following ways
  • Attributes of relations are listed vertically,
    one below the other, instead of horizontally
  • Instead of using variables, lines (links) between
    attributes are used to specify that their values
    should be the same.
  • Links are added automatically on the basis of
    attribute name, and the user can then add or
    delete links
  • By default, a link specifies an inner join, but
    can be modified to specify outer joins.
  • Conditions, values to be printed, as well as
    group by attributes are all specified together in
    a box called the design grid

47
An Example Query in Microsoft Access QBE
  • Example query Find the customer_name,
    account_number and balance for all accounts at
    the Perryridge branch

48
An Aggregation Query in Access QBE
  • Find the name, street and city of all customers
    who have more than one account at the bank

49
Aggregation in Access QBE
  • The row labeled Total specifies
  • which attributes are group by attributes
  • which attributes are to be aggregated upon (and
    the aggregate function).
  • For attributes that are neither group by nor
    aggregated, we can still specify conditions by
    selecting where in the Total row and listing the
    conditions below
  • As in SQL, if group by is used, only group by
    attributes and aggregate results can be output

50
Entity-Relationship Model
  • Design Process
  • Modeling
  • Constraints
  • E-R Diagram
  • Design Issues
  • Weak Entity Sets
  • Extended E-R Features
  • Design of the Bank Database

51
Modeling
  • A database can be modeled as
  • a collection of entities,
  • relationship among entities.
  • An entity is an object that exists and is
    distinguishable from other objects.
  • Example specific person, company, event, plant
  • Entities have attributes
  • Example people have names and addresses
  • An entity set is a set of entities of the same
    type that share the same properties.
  • Example set of all persons, companies, trees,
    holidays

52
Entity Sets customer and loan
customer_id customer_ customer_ customer_
loan_ amount
name street city
number
53
Relationship Sets
  • A relationship is an association among several
    entities
  • Example Hayes depositor A-102 customer
    entity relationship set account entity
  • A relationship set is a mathematical relation
    among n ? 2 entities, each taken from entity sets
  • (e1, e2, en) e1 ? E1, e2 ? E2, , en ?
    Enwhere (e1, e2, , en) is a relationship
  • Example
  • (Hayes, A-102) ? depositor

54
Relationship Set borrower
55
Relationship Sets (Cont.)
  • An attribute can also be property of a
    relationship set.
  • For instance, the depositor relationship set
    between entity sets customer and account may have
    the attribute access-date

56
Degree of a Relationship Set
  • Refers to number of entity sets that participate
    in a relationship set.
  • Relationship sets that involve two entity sets
    are binary (or degree two). Generally, most
    relationship sets in a database system are
    binary.
  • Relationship sets may involve more than two
    entity sets.
  • Relationships between more than two entity sets
    are rare. Most relationships are binary. (More
    on this later.)
  • Example Suppose employees of a bank may have
    jobs (responsibilities) at multiple branches,
    with different jobs at different branches. Then
    there is a ternary relationship set between
    entity sets employee, job, and branch

57
Attributes
  • An entity is represented by a set of attributes,
    that is descriptive properties possessed by all
    members of an entity set.
  • Domain the set of permitted values for each
    attribute
  • Attribute types
  • Simple and composite attributes.
  • Single-valued and multi-valued attributes
  • Example multivalued attribute phone_numbers
  • Derived attributes
  • Can be computed from other attributes
  • Example age, given date_of_birth

Example customer (customer_id,
customer_name, customer_street,
customer_city ) loan (loan_number, amount )
58
Composite Attributes
59
Mapping Cardinality Constraints
  • Express the number of entities to which another
    entity can be associated via a relationship set.
  • Most useful in describing binary relationship
    sets.
  • For a binary relationship set the mapping
    cardinality must be one of the following types
  • One to one
  • One to many
  • Many to one
  • Many to many

60
Mapping Cardinalities
One to one
One to many
Note Some elements in A and B may not be mapped
to any elements in the other set
61
Mapping Cardinalities
Many to one
Many to many
Note Some elements in A and B may not be mapped
to any elements in the other set
62
Keys
  • A super key of an entity set is a set of one or
    more attributes whose values uniquely determine
    each entity.
  • A candidate key of an entity set is a minimal
    super key
  • Customer_id is candidate key of customer
  • account_number is candidate key of account
  • Although several candidate keys may exist, one of
    the candidate keys is selected to be the primary
    key.

63
Keys for Relationship Sets
  • The combination of primary keys of the
    participating entity sets forms a super key of a
    relationship set.
  • (customer_id, account_number) is the super key of
    depositor
  • NOTE this means a pair of entity sets can have
    at most one relationship in a particular
    relationship set.
  • Example if we wish to track all access_dates to
    each account by each customer, we cannot assume a
    relationship for each access. We can use a
    multivalued attribute though
  • Must consider the mapping cardinality of the
    relationship set when deciding what are the
    candidate keys
  • Need to consider semantics of relationship set in
    selecting the primary key in case of more than
    one candidate key

64
E-R Diagrams
  • Rectangles represent entity sets.
  • Diamonds represent relationship sets.
  • Lines link attributes to entity sets and entity
    sets to relationship sets.
  • Ellipses represent attributes
  • Double ellipses represent multivalued attributes.
  • Dashed ellipses denote derived attributes.
  • Underline indicates primary key attributes (will
    study later)

65
E-R Diagram With Composite, Multivalued, and
Derived Attributes
66
Relationship Sets with Attributes
67
Roles
  • Entity sets of a relationship need not be
    distinct
  • The labels manager and worker are called
    roles they specify how employee entities
    interact via the works_for relationship set.
  • Roles are indicated in E-R diagrams by labeling
    the lines that connect diamonds to rectangles.
  • Role labels are optional, and are used to clarify
    semantics of the relationship

68
Cardinality Constraints
  • We express cardinality constraints by drawing
    either a directed line (?), signifying one, or
    an undirected line (), signifying many,
    between the relationship set and the entity set.
  • One-to-one relationship
  • A customer is associated with at most one loan
    via the relationship borrower
  • A loan is associated with at most one customer
    via borrower

69
One-To-Many Relationship
  • In the one-to-many relationship a loan is
    associated with at most one customer via
    borrower, a customer is associated with several
    (including 0) loans via borrower

70
Many-To-One Relationships
  • In a many-to-one relationship a loan is
    associated with several (including 0) customers
    via borrower, a customer is associated with at
    most one loan via borrower

71
Many-To-Many Relationship
  • A customer is associated with several (possibly
    0) loans via borrower
  • A loan is associated with several (possibly 0)
    customers via borrower

72
Participation of an Entity Set in a Relationship
Set
  • Total participation (indicated by double line)
    every entity in the entity set participates in at
    least one relationship in the relationship set
  • E.g. participation of loan in borrower is total
  • every loan must have a customer associated to it
    via borrower
  • Partial participation some entities may not
    participate in any relationship in the
    relationship set
  • Example participation of customer in borrower is
    partial

73
Alternative Notation for Cardinality Limits
  • Cardinality limits can also express participation
    constraints

74
E-R Diagram with a Ternary Relationship
75
Cardinality Constraints on Ternary Relationship
  • We allow at most one arrow out of a ternary (or
    greater degree) relationship to indicate a
    cardinality constraint
  • E.g. an arrow from works_on to job indicates each
    employee works on at most one job at any branch.
  • If there is more than one arrow, there are two
    ways of defining the meaning.
  • E.g a ternary relationship R between A, B and C
    with arrows to B and C could mean
  • 1. each A entity is associated with a unique
    entity from B and C or
  • 2. each pair of entities from (A, B) is
    associated with a unique C entity, and each
    pair (A, C) is associated with a unique B
  • Each alternative has been used in different
    formalisms
  • To avoid confusion we outlaw more than one arrow

76
Design Issues
  • Use of entity sets vs. attributesChoice mainly
    depends on the structure of the enterprise being
    modeled, and on the semantics associated with the
    attribute in question.
  • Use of entity sets vs. relationship setsPossible
    guideline is to designate a relationship set to
    describe an action that occurs between entities
  • Binary versus n-ary relationship setsAlthough it
    is possible to replace any nonbinary (n-ary, for
    n gt 2) relationship set by a number of distinct
    binary relationship sets, a n-ary relationship
    set shows more clearly that several entities
    participate in a single relationship.
  • Placement of relationship attributes

77
Binary Vs. Non-Binary Relationships
  • Some relationships that appear to be non-binary
    may be better represented using binary
    relationships
  • E.g. A ternary relationship parents, relating a
    child to his/her father and mother, is best
    replaced by two binary relationships, father and
    mother
  • Using two binary relationships allows partial
    information (e.g. only mother being know)
  • But there are some relationships that are
    naturally non-binary
  • Example works_on

78
Converting Non-Binary Relationships to Binary Form
  • In general, any non-binary relationship can be
    represented using binary relationships by
    creating an artificial entity set.
  • Replace R between entity sets A, B and C by an
    entity set E, and three relationship sets
  • 1. RA, relating E and A 2.RB, relating E
    and B
  • 3. RC, relating E and C
  • Create a special identifying attribute for E
  • Add any attributes of R to E
  • For each relationship (ai , bi , ci) in R, create
  • 1. a new entity ei in the entity set E
    2. add (ei , ai ) to RA
  • 3. add (ei , bi ) to RB
    4. add (ei , ci ) to RC

79
Converting Non-Binary Relationships (Cont.)
  • Also need to translate constraints
  • Translating all constraints may not be possible
  • There may be instances in the translated schema
    thatcannot correspond to any instance of R
  • Exercise add constraints to the relationships
    RA, RB and RC to ensure that a newly created
    entity corresponds to exactly one entity in each
    of entity sets A, B and C
  • We can avoid creating an identifying attribute by
    making E a weak entity set (described shortly)
    identified by the three relationship sets

80
Mapping Cardinalities affect ER Design
  • Can make access-date an attribute of account,
    instead of a relationship attribute, if each
    account can have only one customer
  • That is, the relationship from account to
    customer is many to one, or equivalently,
    customer to account is one to many

81
Weak Entity Sets
  • An entity set that does not have a primary key is
    referred to as a weak entity set.
  • The existence of a weak entity set depends on the
    existence of a identifying entity set
  • it must relate to the identifying entity set via
    a total, one-to-many relationship set from the
    identifying to the weak entity set
  • Identifying relationship depicted using a double
    diamond
  • The discriminator (or partial key) of a weak
    entity set is the set of attributes that
    distinguishes among all the entities of a weak
    entity set.
  • The primary key of a weak entity set is formed by
    the primary key of the strong entity set on which
    the weak entity set is existence dependent, plus
    the weak entity sets discriminator.

82
Weak Entity Sets (Cont.)
  • We depict a weak entity set by double rectangles.
  • We underline the discriminator of a weak entity
    set with a dashed line.
  • payment_number discriminator of the payment
    entity set
  • Primary key for payment (loan_number,
    payment_number)

83
Weak Entity Sets (Cont.)
  • Note the primary key of the strong entity set is
    not explicitly stored with the weak entity set,
    since it is implicit in the identifying
    relationship.
  • If loan_number were explicitly stored, payment
    could be made a strong entity, but then the
    relationship between payment and loan would be
    duplicated by an implicit relationship defined by
    the attribute loan_number common to payment and
    loan

84
More Weak Entity Set Examples
  • In a university, a course is a strong entity and
    a course_offering can be modeled as a weak entity
  • The discriminator of course_offering would be
    semester (including year) and section_number (if
    there is more than one section)
  • If we model course_offering as a strong entity we
    would model course_number as an attribute.
  • Then the relationship with course would be
    implicit in the course_number attribute

85
Extended E-R Features Specialization
  • Top-down design process we designate
    subgroupings within an entity set that are
    distinctive from other entities in the set.
  • These subgroupings become lower-level entity sets
    that have attributes or participate in
    relationships that do not apply to the
    higher-level entity set.
  • Depicted by a triangle component labeled ISA
    (E.g. customer is a person).
  • Attribute inheritance a lower-level entity set
    inherits all the attributes and relationship
    participation of the higher-level entity set to
    which it is linked.

86
Specialization Example
87
Extended ER Features Generalization
  • A bottom-up design process combine a number of
    entity sets that share the same features into a
    higher-level entity set.
  • Specialization and generalization are simple
    inversions of each other they are represented in
    an E-R diagram in the same way.
  • The terms specialization and generalization are
    used interchangeably.

88
Specialization and Generalization (Cont.)
  • Can have multiple specializations of an entity
    set based on different features.
  • E.g. permanent_employee vs. temporary_employee,
    in addition to officer vs. secretary vs. teller
  • Each particular employee would be
  • a member of one of permanent_employee or
    temporary_employee,
  • and also a member of one of officer, secretary,
    or teller
  • The ISA relationship also referred to as
    superclass - subclass relationship

89
Design Constraints on a Specialization/Generalizat
ion
  • Constraint on which entities can be members of a
    given lower-level entity set.
  • condition-defined
  • Example all customers over 65 years are members
    of senior-citizen entity set senior-citizen ISA
    person.
  • user-defined
  • Constraint on whether or not entities may belong
    to more than one lower-level entity set within a
    single generalization.
  • Disjoint
  • an entity can belong to only one lower-level
    entity set
  • Noted in E-R diagram by writing disjoint next to
    the ISA triangle
  • Overlapping
  • an entity can belong to more than one lower-level
    entity set

90
Design Constraints on a Specialization/Generalizat
ion (Cont.)
  • Completeness constraint -- specifies whether or
    not an entity in the higher-level entity set must
    belong to at least one of the lower-level entity
    sets within a generalization.
  • total an entity must belong to one of the
    lower-level entity sets
  • partial an entity need not belong to one of the
    lower-level entity sets

91
Aggregation
  • Consider the ternary relationship works_on,
    which we saw earlier
  • Suppose we want to record managers for tasks
    performed by an employee at a branch

92
Aggregation (Cont.)
  • Relationship sets works_on and manages represent
    overlapping information
  • Every manages relationship corresponds to a
    works_on relationship
  • However, some works_on relationships may not
    correspond to any manages relationships
  • So we cant discard the works_on relationship
  • Eliminate this redundancy via aggregation
  • Treat relationship as an abstract entity
  • Allows relationships between relationships
  • Abstraction of relationship into new entity
  • Without introducing redundancy, the following
    diagram represents
  • An employee works on a particular job at a
    particular branch
  • An employee, branch, job combination may have an
    associated manager

93
E-R Diagram With Aggregation
94
E-R Design Decisions
  • The use of an attribute or entity set to
    represent an object.
  • Whether a real-world concept is best expressed by
    an entity set or a relationship set.
  • The use of a ternary relationship versus a pair
    of binary relationships.
  • The use of a strong or weak entity set.
  • The use of specialization/generalization
    contributes to modularity in the design.
  • The use of aggregation can treat the aggregate
    entity set as a single unit without concern for
    the details of its internal structure.

95
E-R Diagram for a Banking Enterprise
Write a Comment
User Comments (0)
About PowerShow.com