Database Design 2

download Database Design 2

of 7

Transcript of Database Design 2

  • 7/28/2019 Database Design 2

    1/7

    Database Design 2: Design Method

    Introduction Two-step process for database design Information-level design: completed independentlyof any particular DBMS

    Physical-level design: information-level design adapted for the specific DBMSthat will be used

    Must consider characteristics of the particular DBMS

    User Views User view:set of requirements necessary to support operations of a particular

    database user Cumulative design:supports all user views encountered during design process

    Information-Level Design Method For each user view:

    1. Represent the user view as a collection of tables2. Normalize these tables3. Identify all keys in these tables4. Merge the result of Steps 1 through 3 into the cumulative design

    Represent the User View As a Collection of Tables Step 1: Determine the entities involved and create a separate table for each type

    of entity Step 2: Determine the primary key for each table Step 3: Determine the properties for each entity Step 4: Determine relationships between the entities

    One-to-many

    Many-to-many One-to-one

    One-to-many relationship: include primary key of the one table as a foreign keyin the many table

    Many-to-many relationship: create a new table whose primary key is thecombination of the primary keys of the original tables

    One-to-one relationship: simplest implementation is to treat it as a one-to-manyrelationship

    Normalize the Tables Normalize each table Target is third normal form

    Careful planning in early phases of the process usually rules out need toconsider fourth normal form

    Identify All Keys For each table, identify:

    Primary key Alternate keys Secondary keys Foreign keys

    Alternate key: column(s) that could have been chosen as a primary key but wasnot Secondary keys:columns of interest strictly for retrieval Foreign key: column(s) in one table that is required to match value of the primary

    key for some row in another table or is required to be null Used to create relationships between tables Used to enforce certain types of integrity constraints

  • 7/28/2019 Database Design 2

    2/7

    Types of Primary Keys Natural key:consists of a column that uniquely identifies an entity

    Also called a logical key or an intelligent key Artificial key: column created for an entity to serve solely as the primary key and

    that is visible to users

    Surrogate key: system-generated; usually hidden from users Also called a synthetic key

    Database Design Language (DBDL)

    Table name followed by columns in parentheses Primary key column(s) underlined

    AK identifies alternate keys SK identifies secondary keys FK identifies foreign keys

    Foreign keys followed by an arrow pointing to the table identified by the

    foreign key

    DBDL for the Employee table

  • 7/28/2019 Database Design 2

    3/7

    NORMALIZATION

    First Normal Form Repeating group: multiple entries for a single record Unnormalized relation: contains a repeating group

    Table (relation) in first normal form (1NF) does not contain repeating groups

    Orders (OrderNum, OrderDate, (PartNum, NumOrdered) )

    Sample unnormalized table

    Orders (OrderNum, OrderDate, PartNum, NumOrdered)

    Result of normalization (conversion to first normal form)

  • 7/28/2019 Database Design 2

    4/7

    Second Normal Form

    Sample Orders table

    Orders (OrderNum, OrderDate, PartNum, Description, NumOrdered,QuotedPrice)

    Functional dependencies:OrderNum OrderDatePartNum DescriptionOrderNum, PartNum NumOrdered, QuotedPrice, OrderDate, Description

    Update anomalies Update Inconsistent data Additions Deletions

    Nonkey column (nonkey attribute): not part of primary key

    Table (relation) in second normal form (2NF) Table is in first normal form No nonkey column is dependent on only a portion of primary key

    Dependency diagram: arrows indicate all functional dependencies Arrows above boxes: normal dependencies Arrows below boxes: partial dependencies

    Partial dependencies:only on a portion of the primary key

    Dependences in the Orders table

  • 7/28/2019 Database Design 2

    5/7

    Conversion to second normal form

    Third Normal Form Customer (CustomerNum, CustomerName, Balance, CreditLimit, RepNum,

    LastName, FirstName) Functional dependencies:

    CustomerNum CustomerName, Balance, CreditLimit, RepNum,LastName, FirstName

    RepNum LastName, FirstName

  • 7/28/2019 Database Design 2

    6/7

    Sample Customer table

    2NF tables may still contain problems Redundancy and wasted space Update anomalies

    Update Inconsistent data Additions Deletions

    Determinant: column(s) that determines another column

    Table (relation) in third normal form (3NF) It is in second normal form Its only determinants are candidate keys

    Dependencies in the Customer table

    Correction procedure For each determinant that is not a candidate key, remove from table the

    columns that depend on this determinant Create new table containing all columns from the original table that

    depend on this determinant Make determinant the primary key of new table

  • 7/28/2019 Database Design 2

    7/7

    Conversion to third normal form