首页 > 技术文章 > Relational Database (Enhanced E-R & Model Design)

sabertobih 2022-05-31 08:26 原文

CHAPTER 3: THE ENHANCED E-R MODEL 

supertype/subtype relationships

symbol :

 or

specialization and generalization techniques

Note: multivalued composite attribute was replaced
by an associative entity relationship to another entity
 
CONSTRAINTS IN SUPERTYPE/SUBTYPE
RELATIONSHIPS:

completeness and disjointness constraints 

Completeness Constraints: Whether an instance of a supertype must also be a member of at least one subtype
  • Total Specialization Rule: Yes (double line) 
    •   A patient has to be either an OUTPATIENT or a ResidentPatient
    •     MUST IN
  • Partial Specialization Rule: No (single line)
    •   A vehicle can be a car, a truck, but can be other....
    •        CAN OUT
    •  
Disjointness Constraints: Whether an instance of a supertype may simultaneously be a member of two (or more) subtypes
  • Disjoint Rule: An instance of the supertype can be only ONE of the subtypes
    •   d: ONLY ONE
  • Overlap Rule: An instance of the supertype could be more than one of the subtypes
    •   o: MAYBE BOTH

subtype discriminator: an attribute of the subtype whose values determine the target subtype

  • disjoint - simple attribute
    •   
  • overlapping - a composite attribute whose subparts pertain to different subtypes. Each subpart contains a Boolean value to indicate whether or not the instance belongs to the associated subtype
    •   

CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL

RELATION: named, 2-dimentional table of data, must be in 1st Normal form
  • relations - entity types
  • rows - entity instances
  • columns - attrs 
RELATION (relational database)  vs  RELATIONSHIP (E-R model)
 
FK: [many side] dependent  --->  [one side] parent
 
Keys usually are used as indexes to speed up the
response to user queries 

INTEGRITY CONSTRAINTS

  • Domain Constraints
    •   Allowable values for an attribute. 
  • Entity Integrity
    •   No primary key attribute may be null. All primary key fields MUST have data
  • Action Assertions
    •   Business rules

Referential Integrity

 e.g: Delete Rules
  • Restrict: don't allow delete of parent if dependent exists
  • Cascade: allow delete of parent and auto delete dependent
  • Set-To-Null: delete parent and set FK in dependent side to NULL (not allowed for weak entity)

TRANSFORMING EER DIAGRAMS INTO RELATIONS

Mapping Regular Entities to Relations 

  • simple - directly
  • composite - only use component attr
    •   address (street/ city/ state/ ...) -> street city state
  • multivalued - separate relation with a FK
    •    

Mapping Weak Entities

  • separate relation
  • PK = partial identifier + PK of strong entity
    •  
    •  

Mapping Binary Relationships

  • One-to-Many: FK on Many
  • Many-to-Many: new relation with PK+PK 
    •   
  • One-to-One: FK on Optional 

Mapping Associative Entities 

  • identifier assigned 
    •   PK differs from FK
    •  

  • identifier not assigned
    •   PK + PK / FK + FK

Mapping Unary Relationships

  • ONE TO MANY- RECURSIVE
    •   
  • MANY TO MANY
    •  

        One for entity type: ITEM; One for association relation with PK + PK

Mapping Ternary (and n-ary) Relationships

  •  

Mapping Supertype/Subtype Relationships

 

DATA NORMALIZATION

  • avoid unnecessary duplication of data 
  • decomposing relations to produce well-structured relations
A table should not pertain to more than one entity type -> 1st Normal Form
results in -> data duplication and an unnecessary dependency between the entities

 

FUNCTIONAL DEPENDENCIES AND KEYS

Functional Dependency: The value of one attribute (the determinant) determines the value of another attribute
Candidate Key:
  • A unique identifier. One of the candidate keys
    will become the primary key
  • Each non-key field is functionally dependent on every candidate key(cuz it is unique)

FIRST NORMAL FORM

  • No multivalued attributes
  • Every attribute value is atomic 
  • All relations are 1st Normal Form

SECOND NORMAL FORM

  • 1NF PLUS every non-key attribute is fully functionally dependent on the ENTIRE primary key

THIRD NORMAL FORM

  • 2NF PLUS no transitive dependencies
    (functional dependencies on non-primary-key
    attributes)
  • Solution: Non-key determinant with transitive
    dependencies go into a new table; -> becomes PK in new table an FK in the original one
  •  

     

 
 
 
 
 
 
 
 
 
 

推荐阅读