DBMS Relational Database

					Relational Database Management
              System
Outline
   Conceptual DB Modeling using EER
   Logical DB Modeling
   Normalization
   Physical DB Modeling
   Transaction
Conceptual DB Modeling using EER
- Example COMPANY Database
 We need to create a database schema design based on the
  following (simplified) requirements of the COMPANY Database:
    The company is organized into DEPARTMENTs. Each department
     has a name, number and an employee who manages the
     department. We keep track of the start date of the department
     manager. A department may have several locations.
    Each department controls a number of PROJECTs. Each project has
     a unique name, unique number and is located at a single location.
Conceptual DB Modeling using EER
- Example COMPANY Database (Contd.)
   We store each EMPLOYEE’s social security number, address, salary,
    sex, and birthdate.
       Each employee works for one department but may work on several projects.
       We keep track of the number of hours per week that an employee currently
        works on each project.
       We also keep track of the direct supervisor of each employee.
   Each employee may have a number of DEPENDENTs.
       For each dependent, we keep track of their name, sex, birthdate, and
        relationship to the employee.
Conceptual DB Modeling using EER
- ER Model Concepts
 Entities and Attributes
    Entities are specific objects or things in the mini-world that are represented in
       the database.
          For example the EMPLOYEE John Smith, the Research DEPARTMENT, the
            ProductX PROJECT
    Attributes are properties used to describe an entity.
          For example an EMPLOYEE entity may have the attributes Name, SSN,
            Address, Sex, BirthDate
    A specific entity will have a value for each of its attributes.
          For example a specific employee entity may have Name='John Smith',
            SSN='123456789', Address ='731, Fondren, Houston, TX', Sex='M',
            BirthDate='09-JAN-55‘
    Each attribute has a value set (or data type) associated with it – e.g. integer,
       string, subrange, enumerated type, …
Conceptual DB Modeling using EER
- Types of Attributes (1)
 Simple
    Each entity has a single atomic value for the attribute. For example, SSN or Sex.
 Composite
    The attribute may be composed of several components. For example:
          Address(Apt#, House#, Street, City, State, ZipCode, Country), or
          Name(FirstName, MiddleName, LastName).
          Composition may form a hierarchy where some components are themselves
            composite.
 Multi-valued
    An entity may have multiple values for that attribute. For example, Color of a
       CAR or PreviousDegrees of a STUDENT.
          Denoted as {Color} or {PreviousDegrees}.
Conceptual DB Modeling using EER
- Types of Attributes (2)
 In general, composite and multi-valued attributes may be nested
  arbitrarily to any number of levels, although this is rare.
    For example, PreviousDegrees of a STUDENT is a composite multi-
     valued attribute denoted by {PreviousDegrees (College, Year,
     Degree, Field)}
    Multiple PreviousDegrees values can exist
    Each has four subcomponent attributes:
        College, Year, Degree, Field
Example of a composite attribute
Conceptual DB Modeling using EER
- Entity Types and Key Attributes (1)
 Entities with the same basic attributes are grouped or typed into
  an entity type.
    For example, the entity type EMPLOYEE and PROJECT.
 An attribute of an entity type for which each entity must have a
  unique value is called a key attribute of the entity type.
    For example, SSN of EMPLOYEE.
Conceptual DB Modeling using EER
- Entity Types and Key Attributes (2)
 A key attribute may be composite.
    VehicleTagNumber is a key of the CAR entity type with components
     (Number, State).
 An entity type may have more than one key.
    The CAR entity type may have two keys:
        VehicleIdentificationNumber (popularly called VIN)
        VehicleTagNumber (Number, State), aka license plate number.
 Each key is underlined
Conceptual DB Modeling using EER
- Displaying an Entity type
 In ER diagrams, an entity type is displayed in a rectangular box
 Attributes are displayed in ovals
    Each attribute is connected to its entity type
    Components of a composite attribute are connected to the oval
     representing the composite attribute
    Each key attribute is underlined
    Multivalued attributes displayed in double ovals
 See CAR example on next slide
Conceptual DB Modeling using EER
- Entity Type CAR with two keys and a corresponding Entity Set
Conceptual DB Modeling using EER
- Entity Set
 Each entity type will have a collection of entities stored in the
  database
     Called the entity set
 Previous slide shows three CAR entity instances in the entity
  set for CAR
 Same name (CAR) used to refer to both the entity type and the
  entity set
 Entity set is the current state of the entities of that type that are
  stored in the database
Conceptual DB Modeling using EER
- Initial Design
 Based on the requirements, we can identify four initial entity
  types in the COMPANY database:
      DEPARTMENT
      PROJECT
      EMPLOYEE
      DEPENDENT
 Their initial design is shown on the following slide
 The initial attributes shown are derived from the requirements
  description
Conceptual DB Modeling using EER
- Initial Design
Conceptual DB Modeling using EER
- Refining the initial design by introducing relationships
 The initial design is typically not complete
 Some aspects in the requirements will be represented as
  relationships
 ER model has three main concepts:
    Entities (and their entity types and entity sets)
    Attributes (simple, composite, multivalued)
    Relationships (and their relationship types and relationship sets)
 We introduce relationship concepts next
Conceptual DB Modeling using EER
- Relationships and Relationship Types (1)
 A relationship relates two or more distinct entities with a specific meaning.
    For example, EMPLOYEE John Smith works on the ProductX PROJECT, or
      EMPLOYEE Franklin Wong manages the Research DEPARTMENT.
 Relationships of the same type are grouped or typed into a relationship type.
    For example, the WORKS_ON relationship type in which EMPLOYEEs and
      PROJECTs participate, or the MANAGES relationship type in which
      EMPLOYEEs and DEPARTMENTs participate.
 The degree of a relationship type is the number of participating entity types.
    Both MANAGES and WORKS_ON are binary relationships.
Conceptual DB Modeling using EER
- Relationship instances of the WORKS_FOR N:1 relationship between
EMPLOYEE and DEPARTMENT
Conceptual DB Modeling using EER
- Relationship instances of the M:N WORKS_ON relationship between
EMPLOYEE and PROJECT
Conceptual DB Modeling using EER
- Relationship type vs. relationship set (1)
 Relationship Type:
    Is the schema description of a relationship
    Identifies the relationship name and the participating entity types
    Also identifies certain relationship constraints
 Relationship Set:
    The current set of relationship instances represented in the database
    The current state of a relationship type
Conceptual DB Modeling using EER
- Relationship type vs. relationship set (2)
 Previous figures displayed the relationship sets
 Each instance in the set relates individual participating entities –
  one from each participating entity type
 In ER diagrams, we represent the relationship type as follows:
    Diamond-shaped box is used to display a relationship type
    Connected to the participating entity types via straight lines
Conceptual DB Modeling using EER
- Refining the COMPANY database schema by introducing
relationships
 By examining the requirements, six relationship types are identified
 All are binary relationships( degree 2)
 Listed below with their participating entity types:
        WORKS_FOR (between EMPLOYEE, DEPARTMENT)
        MANAGES (also between EMPLOYEE, DEPARTMENT)
        CONTROLS (between DEPARTMENT, PROJECT)
        WORKS_ON (between EMPLOYEE, PROJECT)
        SUPERVISION (between EMPLOYEE (as subordinate), EMPLOYEE (as supervisor))
        DEPENDENTS_OF (between EMPLOYEE, DEPENDENT)
Conceptual DB Modeling using EER
- ER DIAGRAM – Relationship Types are:
WORKS_FOR, MANAGES, WORKS_ON, CONTROLS, SUPERVISION, DEPENDENTS_OF
Conceptual DB Modeling using EER
- Discussion on Relationship Types
 In the refined design, some attributes from the initial entity types are refined into
  relationships:
     Manager of DEPARTMENT -> MANAGES
     Works_on of EMPLOYEE -> WORKS_ON
     Department of EMPLOYEE -> WORKS_FOR
     etc
 In general, more than one relationship type can exist between the same participating
  entity types
     MANAGES and WORKS_FOR are distinct relationship types between
       EMPLOYEE and DEPARTMENT
     Different meanings and different relationship instances.
Conceptual DB Modeling using EER
- Recursive Relationship Type
 An relationship type whose with the same participating entity type in distinct roles
 Example: the SUPERVISION relationship
 EMPLOYEE participates twice in two distinct roles:
    supervisor (or boss) role
    supervisee (or subordinate) role
 Each relationship instance relates two distinct EMPLOYEE entities:
    One employee in supervisor role
    One employee in supervisee role
Conceptual DB Modeling using EER
- Weak Entity Types
 An entity that does not have a key attribute
 A weak entity must participate in an identifying relationship type with an owner or
  identifying entity type
 Entities are identified by the combination of:
     A partial key of the weak entity type
     The particular entity they are related to in the identifying entity type
 Example:
     A DEPENDENT entity is identified by the dependent’s first name, and the
       specific EMPLOYEE with whom the dependent is related
     Name of DEPENDENT is the partial key
     DEPENDENT is a weak entity type
     EMPLOYEE is its identifying entity type via the identifying relationship type
       DEPENDENT_OF
Conceptual DB Modeling using EER
- Constraints on Relationships
 Constraints on Relationship Types
    (Also known as ratio constraints)
    Cardinality Ratio (specifies maximum participation)
         One-to-one (1:1)
         One-to-many (1:N) or Many-to-one (N:1)
         Many-to-many (M:N)
    Existence Dependency Constraint (specifies minimum participation) (also called
     participation constraint)
         zero (optional participation, not existence-dependent)
         one or more (mandatory participation, existence-dependent)
Conceptual DB Modeling using EER
- Many-to-one (N:1) Relationship
Conceptual DB Modeling using EER
- Many-to-many (M:N) Relationship
Attributes of Relationship types
 A relationship type can have attributes:
    For example, HoursPerWeek of WORKS_ON
    Its value for each relationship instance describes the number of hours
     per week that an EMPLOYEE works on a PROJECT.
        A value of HoursPerWeek depends on a particular (employee, project)
         combination
    Most relationship attributes are used with M:N relationships
        In 1:N relationships, they can be transferred to the entity type on the N-side
         of the relationship
Conceptual DB Modeling using EER
- Example Attribute of a Relationship Type
Conceptual DB Modeling using EER
- Notation for Constraints on Relationships
 Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N
     Shown by placing appropriate numbers on the relationship edges.
 Participation constraint (on each participating entity type): total
  (called existence dependency) or partial.
     Total shown by double line, partial by single line.
 NOTE: These are easy to specify for Binary Relationship Types.
Conceptual DB Modeling using EER
- Notation for Constraints on Relationships
 1:1 Example
    MANAGES (EMPLOYEE:DEPARTMENT)
 1:N Example
    WORKS_FOR (DEPARTMENT:EMPLOYEE)
 N:M Example
    WORKS_ON (EMPLOYEE:PROJECT)
Conceptual DB Modeling using EER
- Notation for Constraints on Relationships
 Participation constraint:
    Total participation
        Every participant entity must be related to the relation.
        EMPLOYEE in WORKS_FOR
    Partial participation
        Some participant entities may be related to the relation, but not necessary
         all.
        EMPLOYEE in MANAGES
Conceptual DB Modeling using EER
- Subclasses and Superclasses
 An entity type may have additional meaningful subgroupings of its entities
    Example: EMPLOYEE may be further grouped into:
          SECRETARY, ENGINEER, TECHNICIAN, …
              – Based on the EMPLOYEE’s Job
          MANAGER
              – EMPLOYEEs who are managers
          SALARIED_EMPLOYEE, HOURLY_EMPLOYEE
              – Based on the EMPLOYEE’s method of pay
 EER diagrams extend ER diagrams to represent these additional subgroupings,
  called subclasses or subtypes
Conceptual DB Modeling using EER
- Subclasses and Superclasses
Conceptual DB Modeling using EER
- Subclasses and Superclasses
   Each of these subgroupings is a subset of EMPLOYEE entities
   Each is called a subclass of EMPLOYEE
   EMPLOYEE is the superclass for each of these subclasses
   These are called superclass/subclass relationships:
        EMPLOYEE/SECRETARY
        EMPLOYEE/TECHNICIAN
        EMPLOYEE/MANAGER
        …
Conceptual DB Modeling using EER
- Subclasses and Superclasses
 These are also called IS-A relationships
    SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, ….
 Note: An entity that is member of a subclass represents the same real-world entity as
  some member of the superclass:
    The subclass member is the same entity in a distinct specific role
    An entity cannot exist in the database merely by being a member of a subclass;
      it must also be a member of the superclass
    A member of the superclass can be optionally included as a member of any
      number of its subclasses
Conceptual DB Modeling using EER
- Subclasses and Superclasses
 Examples:
     A salaried employee who is also an engineer belongs to the two subclasses:
           ENGINEER, and
           SALARIED_EMPLOYEE
     A salaried employee who is also an engineering manager belongs to the three
        subclasses:
           MANAGER,
           ENGINEER, and
           SALARIED_EMPLOYEE
 It is not necessary that every entity in a superclass be a member of some subclass
Conceptual DB Modeling using EER
- Representing Specialization in EER Diagrams
Conceptual DB Modeling using EER
- Attribute Inheritance in Superclass / Subclass Relationships
 An entity that is member of a subclass inherits
    All attributes of the entity as a member of the superclass
    All relationships of the entity as a member of the superclass
 Example:
    In the previous slide, SECRETARY (as well as TECHNICIAN and
     ENGINEER) inherit the attributes Name, SSN, …, from EMPLOYEE
    Every SECRETARY entity will have values for the inherited attributes
Conceptual DB Modeling using EER
- Specialization
 Specialization is the process of defining a set of subclasses of a
  superclass
 The set of subclasses is based upon some distinguishing
  characteristics of the entities in the superclass
    Example: {SECRETARY, ENGINEER, TECHNICIAN} is a
     specialization of EMPLOYEE based upon job type.
        May have several specializations of the same superclass
Conceptual DB Modeling using EER
- Specialization
 Example: Another specialization of EMPLOYEE based on method of pay is
  {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}.
    Superclass/subclass relationships and specialization can be diagrammatically
      represented in EER diagrams
    Attributes of a subclass are called specific or local attributes.
         For example, the attribute TypingSpeed of SECRETARY
    The subclass can also participate in specific relationship types.
         For example, a relationship BELONGS_TO of HOURLY_EMPLOYEE
Conceptual DB Modeling using EER
- Specialization
Conceptual DB Modeling using EER
- Generalization
 Generalization is the reverse of the specialization process
 Several classes with common features are generalized into a superclass;
    original classes become its subclasses
 Example: CAR, TRUCK generalized into VEHICLE;
    both CAR, TRUCK become subclasses of the superclass VEHICLE.
    We can view {CAR, TRUCK} as a specialization of VEHICLE
    Alternatively, we can view VEHICLE as a generalization of CAR and TRUCK
Conceptual DB Modeling using EER -
Generalization
Conceptual DB Modeling using EER
- Generalization and Specialization
 Diagrammatic notation are sometimes used to distinguish
  between generalization and specialization
    Arrow pointing to the generalized superclass represents a
     generalization
    Arrows pointing to the specialized subclasses represent a
     specialization
    We do not use this notation because it is often subjective as to which
     process is more appropriate for a particular situation
    We advocate not drawing any arrows
Conceptual DB Modeling using EER
- A single subclass example
Conceptual DB Modeling using EER
- Constraints on Specialization and Generalization
 Two basic constraints can apply to a
  specialization/generalization:
    Disjointness Constraint:
    Completeness Constraint:
Conceptual DB Modeling using EER
- Constraints on Specialization and Generalization
 Disjointness Constraint:
    Specifies that the subclasses of the specialization must be disjoint:
        an entity can be a member of at most one of the subclasses of the
         specialization
    Specified by d in EER diagram
    If not disjoint, specialization is overlapping:
        that is the same entity may be a member of more than one subclass of the
         specialization
    Specified by o in EER diagram
Conceptual DB Modeling using EER
- Example of disjoint Specialization
Conceptual DB Modeling using EER
- Example of overlapping Specialization
Conceptual DB Modeling using EER
- Constraints on Specialization and Generalization
 Completeness Constraint:
    Total specifies that every entity in the superclass must be a member
     of some subclass in the specialization/generalization
    Shown in EER diagrams by a double line
    Partial allows an entity not to belong to any of the subclasses
    Shown in EER diagrams by a single line
Conceptual DB Modeling using EER
- Constraints on Specialization and Generalization
 Hence, we have four types of specialization/generalization:
      Disjoint, total
      Disjoint, partial
      Overlapping, total
      Overlapping, partial
 Note: Generalization usually is total because the superclass is
  derived from the subclasses.
Conceptual DB Modeling using EER
- Example of disjoint partial Specialization
Conceptual DB Modeling using EER
- Example of overlapping total Specialization
Conceptual DB Modeling using EER
- Shared Subclass “Engineering_Manager”
Logical DB Modeling - ER-to-Relational
Mapping Algorithm
 Step 1: Mapping of Regular Entity Types.
    For each regular (strong) entity type E in the ER schema, create a relation R
       that includes all the simple attributes of E.
    Choose one of the key attributes of E as the primary key for R.
    If the chosen key of E is composite, the set of simple attributes that form it will
       together form the primary key of R.
 Example: We create the relations EMPLOYEE, DEPARTMENT, and PROJECT in the
  relational schema corresponding to the regular entities in the ER diagram.
    SSN, DNUMBER, and PNUMBER are the primary keys for the relations
       EMPLOYEE, DEPARTMENT, and PROJECT as shown.
FIGURE 7.1
The ER conceptual schema diagram for the COMPANY database.
FIGURE 7.2
Result of mapping the COMPANY ER schema into a relational schema.
  Logical DB Modeling - ER-to-Relational Mapping Algorithm (contd.)
 Step 2: Mapping of Weak Entity Types
    For each weak entity type W in the ER schema with owner entity type E, create
       a relation R & include all simple attributes (or simple components of composite
       attributes) of W as attributes of R.
    Also, include as foreign key attributes of R the primary key attribute(s) of the
       relation(s) that correspond to the owner entity type(s).
    The primary key of R is the combination of the primary key(s) of the owner(s)
       and the partial key of the weak entity type W, if any.
 Example: Create the relation DEPENDENT in this step to correspond to the weak
  entity type DEPENDENT.
    Include the primary key SSN of the EMPLOYEE relation as a foreign key
       attribute of DEPENDENT (renamed to ESSN).
    The primary key of the DEPENDENT relation is the combination {ESSN,
       DEPENDENT_NAME} because DEPENDENT_NAME is the partial key of
       DEPENDENT.
Logical DB Modeling - ER-to-Relational Mapping Algorithm (contd.)
 Step 3: Mapping of Binary 1:1 Relation Types
    For each binary 1:1 relationship type R in the ER schema, identify the relations
      S and T that correspond to the entity types participating in R.
 There are three possible approaches:
   1. Foreign Key approach: Choose one of the relations-say S-and include a
      foreign key in S the primary key of T. It is better to choose an entity type with
      total participation in R in the role of S.
         Example: 1:1 relation MANAGES is mapped by choosing the participating
            entity type DEPARTMENT to serve in the role of S, because its
            participation in the MANAGES relationship type is total.
   2. Merged relation option: An alternate mapping of a 1:1 relationship type is
      possible by merging the two entity types and the relationship into a single
      relation. This may be appropriate when both participations are total.
   3. Cross-reference or relationship relation option: The third alternative is to set
      up a third relation R for the purpose of cross-referencing the primary keys of the
      two relations S and T representing the entity types.
Logical DB Modeling - ER-to-Relational Mapping Algorithm (contd.)

 Step 4: Mapping of Binary 1:N Relationship Types.
     For each regular binary 1:N relationship type R, identify the relation S that
       represent the participating entity type at the N-side of the relationship type.
     Include as foreign key in S the primary key of the relation T that represents the
       other entity type participating in R.
     Include any simple attributes of the 1:N relation type as attributes of S.
 Example: 1:N relationship types WORKS_FOR, CONTROLS, and SUPERVISION in
  the figure.
     For WORKS_FOR we include the primary key DNUMBER of the DEPARTMENT
       relation as foreign key in the EMPLOYEE relation and call it DNO.
Logical DB Modeling - ER-to-Relational Mapping Algorithm (contd.)
 Step 5: Mapping of Binary M:N Relationship Types.
    For each regular binary M:N relationship type R, create a new relation S to represent
      R.
    Include as foreign key attributes in S the primary keys of the relations that represent
      the participating entity types; their combination will form the primary key of S.
    Also include any simple attributes of the M:N relationship type (or simple
      components of composite attributes) as attributes of S.
 Example: The M:N relationship type WORKS_ON from the ER diagram is mapped by
  creating a relation WORKS_ON in the relational database schema.
    The primary keys of the PROJECT and EMPLOYEE relations are included as
      foreign keys in WORKS_ON and renamed PNO and ESSN, respectively.
    Attribute HOURS in WORKS_ON represents the HOURS attribute of the relation
      type. The primary key of the WORKS_ON relation is the combination of the foreign
      key attributes {ESSN, PNO}.
    Logical DB Modeling - ER-to-Relational Mapping Algorithm (contd.)

 Step 6: Mapping of Multivalued attributes.
    For each multivalued attribute A, create a new relation R.
    This relation R will include an attribute corresponding to A, plus the primary key
      attribute K-as a foreign key in R-of the relation that represents the entity type of
      relationship type that has A as an attribute.
    The primary key of R is the combination of A and K. If the multivalued attribute is
      composite, we include its simple components.
 Example: The relation DEPT_LOCATIONS is created.
    The attribute DLOCATION represents the multivalued attribute LOCATIONS of
      DEPARTMENT, while DNUMBER-as foreign key-represents the primary key of the
      DEPARTMENT relation.
    The primary key of R is the combination of {DNUMBER, DLOCATION}.
    Logical DB Modeling - ER-to-Relational Mapping Algorithm (contd.)

 Step 7: Mapping of N-ary Relationship Types.
    For each n-ary relationship type R, where n>2, create a new relationship S to
      represent R.
    Include as foreign key attributes in S the primary keys of the relations that
      represent the participating entity types.
    Also include any simple attributes of the n-ary relationship type (or simple
      components of composite attributes) as attributes of S.
 Example: The relationship type SUPPY in the ER on the next slide.
    This can be mapped to the relation SUPPLY shown in the relational schema,
      whose primary key is the combination of the three foreign keys {SNAME,
      PARTNO, PROJNAME}
Logical DB Modeling - Mapping EER Model Constructs to
Relations
 Step8: Options for Mapping Specialization or Generalization.
    Convert each specialization with m subclasses {S1, S2,….,Sm} and
     generalized superclass C, where the attributes of C are {k,a1,…an} and k is
     the (primary) key, into relational schemas using one of the four following
     options:
        Option 8A: Multiple relations-Superclass and subclasses
        Option 8B: Multiple relations-Subclass relations only
        Option 8C: Single relation with one type attribute
        Option 8D: Single relation with multiple type attributes
Logical DB Modeling - Mapping EER Model Constructs to
Relations
 Option 8A: Multiple relations-Superclass and subclasses
    Create a relation L for C with attributes Attrs(L) = {k,a1,…an} and PK(L) = k.
      Create a relation Li for each subclass Si, 1 < i < m, with the attributesAttrs(Li) =
      {k} U {attributes of Si} and PK(Li)=k. This option works for any specialization
      (total or partial, disjoint of over-lapping).
 Option 8B: Multiple relations-Subclass relations only
    Create a relation Li for each subclass Si, 1 < i < m, with the attributes Attr(Li) =
      {attributes of Si} U {k,a1…,an} and PK(Li) = k. This option only works for a
      specialization whose subclasses are total (every entity in the superclass must
      belong to (at least) one of the subclasses).
FIGURE 4.4
EER diagram notation for an attribute-defined specialization on JobType.
FIGURE 7.4
Options for mapping specialization or generalization.
(a) Mapping the EER schema in Figure 4.4 using option 8A.
FIGURE 4.3
Generalization. (b) Generalizing CAR and TRUCK into the superclass VEHICLE.
FIGURE 7.4
Options for mapping specialization or generalization.
(b) Mapping the EER schema in Figure 4.3b using option 8B.
Logical DB Modeling - Mapping EER Model Constructs to Relations (contd.)

  Option 8C: Single relation with one type attribute
     Create a single relation L with attributes Attrs(L) = {k,a1,…an} U {attributes of S1}
       U…U {attributes of Sm} U {t} and PK(L) = k. The attribute t is called a type (or
       discriminating) attribute that indicates the subclass to which each tuple belongs
  Option 8D: Single relation with multiple type attributes
     Create a single relation schema L with attributes Attrs(L) = {k,a1,…an} U {attributes
       of S1} U…U {attributes of Sm} U {t1, t2,…,tm} and PK(L) = k. Each ti, 1 < I < m, is
       a Boolean type attribute indicating whether a tuple belongs to the subclass Si.
FIGURE 4.4
EER diagram notation for an attribute-defined specialization on JobType.
FIGURE 7.4
Options for mapping specialization or generalization.
(c) Mapping the EER schema in Figure 4.4 using option 8C.
FIGURE 4.5
EER diagram notation for an overlapping (non-disjoint) specialization.
FIGURE 7.4
Options for mapping specialization or generalization. (d) Mapping Figure
4.5 using option 8D with Boolean type fields Mflag and Pflag.
Normalization
 Why we need to normalized the DB?
Normalization - Functional Dependencies (1)
 Functional dependencies (FDs)
    Are used to specify formal measures of the "goodness" of relational
     designs
    And keys are used to define normal forms for relations
    Are constraints that are derived from the meaning and
     interrelationships of the data attributes
 A set of attributes X functionally determines a set of attributes
  Y if the value of X determines a unique value for Y
Normalization - Functional Dependencies (2)
 X -> Y holds if whenever two tuples have the same value for X, they must have the
  same value for Y
    For any two tuples t1 and t2 in any relation instance r(R): If t1[X]=t2[X], then
       t1[Y]=t2[Y]
 X -> Y in R specifies a constraint on all relation instances r(R)
 Written as X -> Y; can be displayed graphically on a relation schema as in Figures. (
  denoted by the arrow: ).
 FDs are derived from the real-world constraints on the attributes
Normalization - Examples of FD constraints
 Social security number determines employee name
    SSN -> ENAME
 Project number determines project name and location
    PNUMBER -> {PNAME, PLOCATION}
 Employee ssn and project number determines the hours per
  week that the employee works on the project
    {SSN, PNUMBER} -> HOURS
Normalization
 An FD is a property of the attributes in the schema R
 The constraint must hold on every relation instance r(R)
 If K is a key of R, then K functionally determines all attributes in
  R
     (since we never have two distinct tuples with t1[K]=t2[K])
Normalization - Normalization of Relations (1)
 Normalization:
    The process of decomposing unsatisfactory "bad" relations by
     breaking up their attributes into smaller relations


 Normal form:
    Condition using keys and FDs of a relation to certify whether a
     relation schema is in a particular normal form
Normalization - Normalization of Relations (2)
 2NF, 3NF, BCNF
    based on keys and FDs of a relation schema
 4NF
    based on keys, multi-valued dependencies : MVDs; 5NF based on
     keys, join dependencies : JDs (Chapter 11)
 Additional properties may be needed to ensure a good relational
  design (lossless join, dependency preservation; Chapter 11)
Normalization - Practical Use of Normal Forms
 Normalization is carried out in practice so that the resulting designs are of high
  quality and meet the desirable properties
 The practical utility of these normal forms becomes questionable when the
  constraints on which they are based are hard to understand or to detect
 The database designers need not normalize to the highest possible normal form
    (usually up to 3NF, BCNF or 4NF)
 Denormalization:
    The process of storing the join of higher normal form relations as a base
       relation—which is in a lower normal form
Normalization - Definitions of Keys and Attributes Participating
in Keys (1)
 A superkey of a relation schema R = {A1, A2, ...., An} is a set
  of attributes S subset-of R with the property that no two tuples
  t1 and t2 in any legal relation state r of R will have t1[S] = t2[S]

 A key K is a superkey with the additional property that removal
  of any attribute from K will cause K not to be a superkey any
  more.
Normalization - Definitions of Keys and Attributes Participating
in Keys (2)
 If a relation schema has more than one key, each is called a
  candidate key.
    One of the candidate keys is arbitrarily designated to be the primary
     key, and the others are called secondary keys.
 A Prime attribute must be a member of some candidate key
 A Nonprime attribute is not a prime attribute—that is, it is not a
  member of any candidate key.
Normalization - First Normal Form
 Disallows
    composite attributes
    multivalued attributes
    nested relations; attributes whose values for an individual tuple are
     non-atomic


 Considered to be part of the definition of relation
Normalization - Normalization into 1NF
Normalization - Normalization nested relations into 1NF
Normalization - Second Normal Form (1)
 Uses the concepts of FDs, primary key
 Definitions
    Prime attribute: An attribute that is member of the primary key K
    Full functional dependency: a FD Y -> Z where removal of any attribute from
      Y means the FD does not hold any more
 Examples:
    {SSN, PNUMBER} -> HOURS is a full FD since neither SSN -> HOURS nor
      PNUMBER -> HOURS hold
    {SSN, PNUMBER} -> ENAME is not a full FD (it is called a partial dependency )
      since SSN -> ENAME also holds
Normalization - Second Normal Form (2)
 A relation schema R is in second normal form (2NF) if every
  non-prime attribute A in R is fully functionally dependent on the
  primary key
 R can be decomposed into 2NF relations via the process of
  2NF normalization
Normalization - Normalizing into 2NF and 3NF
Normalization - Normalization into 2NF and 3NF
Normalization - Third Normal Form (1)
 Definition:
    Transitive functional dependency: a FD X -> Z that can be derived
     from two FDs X -> Y and Y -> Z
 Examples:
    SSN -> DMGRSSN is a transitive FD
        Since SSN -> DNUMBER and DNUMBER -> DMGRSSN hold
    SSN -> ENAME is non-transitive
        Since there is no set of attributes X where SSN -> X and X -> ENAME
Normalization - Two relation schemas suffering from update
anomalies
FIGURE 10.10 Normalizing into 2NF and 3NF.
(a) Normalizing EMP_PROJ into 2NF relations
(b) Normalizing EMP_DEPT into 3NF relations.
Normalization - Third Normal Form (2)
 A relation schema R is in third normal form (3NF) if it is in 2NF and no non-prime
  attribute A in R is transitively dependent on the primary key
 R can be decomposed into 3NF relations via the process of 3NF normalization
 NOTE:
    In X -> Y and Y -> Z, with X as the primary key, we consider this a problem only
        if Y is not a candidate key.
    When Y is a candidate key, there is no problem with the transitive dependency .
    E.g., Consider EMP (SSN, Emp#, Salary ).
            Here, SSN -> Emp# -> Salary and Emp# is a candidate key.
Physical DB Modeling
 Identify the attributes in the selection/join condition.
 They are the candidate attributes to be indexed.
Physical DB Modeling
 Identify the attributes in the selection condition of
  insert/update/delete operations.
 They are the candidate attributes to be indexed.



 Also, identify the attributes which their values are to be changed
 They are the candidate attributes NOT to be indexed.
Physical DB Modeling
 Determine the expected frequency, time constraint, each query
  to be invoked.
 Then, common sense 
 Apply 80-20 rule.
Physical DB Modeling - Oracle
 Oracle automatically creates an index for each UNIQUE or
  PRIMARY KEY declaration.
 INDEX_TYPE: NORMAL -> B-TREE (B+ tree)
 Null values are not indexed.
 Statistics terms
    BLEVEL: depth of the index tree
    LEAF_BLOCKS: number of leaf blocks in the index
    DISTINCT_KEYS: number of the distinct index key
Physical DB Modeling - Oracle
 Composite
      create index emp_idx on employee(name, id);
      Type of this index?
      Selective: id vs name?
      If only id is referred in the WHERE clause?
      Skip scanning is used when the leading column is not referred, so the
       query still utilizes the composite index.
Physical DB Modeling - Oracle
 Bitmap
      FNAME     LNAME      ID   SECTION   MGR   GDR
      David     Smith      10   ADT       DS    M
      Belinda   Anderson   20   HRM       MD    F
      Peter     Neuman     30   ADT       DS    M
      Michael   Ducunal    40   PRS       DS    M
      Windy     Lucida     50   ADT       MD    F
      Jenny     Eastwood   60   ADT       DS    F



 SELECT        id, fname, lname, mgr,
 FROM          emp
 WHERE         section = ‘ADT’ AND mgr = ‘DS’ AND gdr = ‘M’;
Physical DB Modeling - Oracle
 Bitmap
     ADT    HRM   PRS   M     F   DS       MD
      1      0     0    1     0        1        0
                        0     1
      0      1     0                   0        1
                        1     0
      1      0     0                   1        0
                        1     0
      0      0     1    0     1        1        0

      1      0     0    0     1        0        1

      1      0     0                   1        0




           SECTION          GDR        MGR
Physical DB Modeling - Oracle
 Bitmap            ID   FNAME   LNAME    MGR

          101011    10   David   Smith    DS

                    30   Peter   Neuman   DS
          101101
      AND 101100
          101000
Physical DB Modeling - Microsoft SQL Server
 Clustered index
    B-tree
 Non-clustered index
    Flat file
Physical DB Modeling - MySQL
 The applicability of the indexes is depended on the file (storage
  engine) used.
    MyISAM: Btree, Rtree
    InnoDB: Btree
    Memory/Heap: Hash, Btree
Physical DB Modeling - Denormalization
 Suppose that the department data are always used with
  employees data.
 Also, employees are rarely move from a department to another.
 There are also rarely changes in department data.
 Denomalization may be applied.
Physical DB Modeling - Full-text index
   Typos
   Stop words
   Stemming
   Rank query
Transaction Management
 A Transaction:
    Logical unit of database processing that includes one or more access
      operations (read -retrieval, write - insert or update, delete).
 A transaction (set of operations) may be stand-alone specified in a high
  level language like SQL submitted interactively, or may be embedded
  within a program.
 Transaction boundaries:
    Begin and End transaction.
 An application program may contain several transactions separated by
  the Begin and End transaction boundaries.
Transaction Management - needs
Transaction Management - ACID
ACID properties:
 Atomicity: A transaction is an atomic unit of processing; it is either performed in its
   entirety or not performed at all.
 Consistency preservation: A correct execution of the transaction must take the
   database from one consistent state to another.
 Isolation: A transaction should not make its updates visible to other transactions until
   it is committed; this property, when enforced strictly, solves the temporary update
   problem and makes cascading rollbacks of transactions.
 Durability or permanency: Once a transaction changes the database and the
   changes are committed, these changes must never be lost because of subsequent
   failure.
Transaction Management
 Locking mechanism
 Time-stamp ordering
  Transaction Management - PHP & Oracle1
                                               CREATE SEQUENCE category_id_seq
  CREATE SEQUENCE                              INCREMENT BY 1;
     blog_id_seq
  INCREMENT BY 1;                              CREATE TABLE categories (
                                                  id NUMBER PRIMARY KEY,
                                                  name VARCHAR2(30) UNIQUE
  CREATE TABLE blogs (                         );
     id NUMBER PRIMARY KEY,
     title VARCHAR2(200),                      CREATE TABLE blogs_to_categories (
     date_published DATE,                         blog_id INTEGER NOT NULL
                                                  REFERENCES blogs(id),
     text CLOB
                                                  category_id INTEGER NOT NULL
  );                                              REFERENCES categories(id),
                                                  PRIMARY KEY (blog_id, category_id)
                                               );

1from   http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_transactions.html
 Transaction Management - PHP & Oracle
<?php                                              $stmt = oci_parse($conn,$sql);
$conn = oci_connect('SCOTT','TIGER') or die;
                                                   foreach ( $categories as $category ) {
// Some categories                                   oci_bind_by_name($stmt,':category',
$categories = array(                               $category,30);
   'php',
   'oracle',                                         // Note the OCI_DEFAULT parameter
   'programming',                                    if ( !oci_execute($stmt,OCI_DEFAULT) ) {
   'web',                                                // If we have a problem, rollback then die
   'this string is too long for the name column'         oci_rollback($conn);
);                                                       die;
                                                     }
$sql = "INSERT INTO categories
                                         }
     (id, name)
     VALUES                              // If we got this far, it's OK to commit
     (category_id_seq.nextval,:category) oci_commit($conn);// etc.
     ";                                  ?>
                   Two modes: OCI_DEFAULT or OCI_COMMIT_ON_SUCCESS
Summary
   Conceptual DB Modeling using EER
   Logical DB Modeling
   Normalization
   Physical DB Modeling
   Transaction
   DB Recovery

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:57
posted:8/19/2011
language:English
pages:117