Db Design Clc

Embed Size (px)

Citation preview

  • 8/3/2019 Db Design Clc

    1/25

    Dr Tran Thi Song Minh National Economics University

    4.3 CREATING A DATABASEENVIRONMENT

  • 8/3/2019 Db Design Clc

    2/25

    Dr Tran Thi Song Minh National Economics University

    KEY TERMS

    A Database = a collection of information that youorganize and access according to the logical structure ofthat information.

    A relational database = a database that uses a seriesof logically related two-dimensional tables or files to store

    information in the form of a database. A relation = often used to refer to a file while designing

    a DB

    A Entity class = A concept typically people, places, orthings about which you wish to store information and thatyou can identify with an unique key (called a primary key)

    A primary key= A field (or group of fields in somecases) that uniquely describes each record/ an instance.

    An instance = An occurrence of an entity class that canbe uniquely described with a primary key.

  • 8/3/2019 Db Design Clc

    3/25

    Dr Tran Thi Song Minh National Economics University

    KEY TERMS (Contd)

    A intersection relation/ a composite relation = arelation you create to eliminate a many-to-manyrelationship.

    A composite primary key= a primary key thatconsists of the primary fields from the twointersecting relations.

    A foreign key= a primary key of one file (relation)that appears in another file (relation).

  • 8/3/2019 Db Design Clc

    4/25

    Dr Tran Thi Song Minh National Economics University

    FOUR STEPS IN DESIGNING ANDBUILDING A RELATIONAL DATABASE

    1. Defining entity classes and primarykeys

    2. Defining relationships and cardinalityamong entity classes

    3. Defining information (fields) for eachrelation

    4. Using a data definition language tocreate your database.

  • 8/3/2019 Db Design Clc

    5/25

    Dr Tran Thi Song Minh National Economics University

    ENTITY-RELATIONSHIP DIAGRAMSYMBOLS

    Entity class

    Single relationship

    Multiple relationship

    A relationship

    Zero or optional relationship

  • 8/3/2019 Db Design Clc

    6/25

    Dr Tran Thi Song Minh National Economics University

    A SUPPLY CHAIN MANAGEMENT REPORTFOR SOLOMON ENTERPRISES

    SOLOMON ENTERPRISES

    Supply Report Ending October 14, 2005

    CONCRETE RAW MATERIAL SUPPLIER

    Type Name ID Name Unit QOH ID Name1 Home B Cement paste 1 400 412 Wesley Enterprises

    C Sand 2 1200 444 Juniper Sand & Gravel

    A Water 1.5 9999 999 N/A

    Total 4.5

    2 Comm B Cement paste 1 400 412 Wesley Enterprises

    C Sand 2 1200 444 Juniper Sand & Gravel

    A Water 1 9999 999 N/A

    Total 4

  • 8/3/2019 Db Design Clc

    7/25

    Dr Tran Thi Song Minh National Economics University

    BUSINESS RULES

    1. A given concrete type will have many rawmaterials in it.

    2. A given raw material may appear in many

    types of concrete.3. Each raw material has one and only one

    supplier.

    4. A supplier may provide many raw

    materials. Solomon may have a supplier inits database that doesnt currently provideany raw materials.

  • 8/3/2019 Db Design Clc

    8/25

    Dr Tran Thi Song Minh National Economics University

    STEP 1: Defining entity classes andprimary keys

    Entity classes Primary Key

    Concrete Type Concrete Type (ID)

    Raw Material Raw Material ID

    Supplier Suppler ID

    Goal

    To define the various entity classes and the primary keysthat uniquely define each record or instance within each entityclass.

  • 8/3/2019 Db Design Clc

    9/25

    Dr Tran Thi Song Minh National Economics University

    STEP 2: Defining relationshipsamong entity classes

    CONCRETE TYPE RAW MATERIAL

    SUPPLIER

    provides a

    is composed of

    An Intersection Relation should becreated to remove this many-to-

    many relationship

    Goal

    To define the relationships among the entity classes.

  • 8/3/2019 Db Design Clc

    10/25

    Dr Tran Thi Song Minh National Economics University

    READING THE Entity-RelationshipDIAGRAM

    A Concrete Type is composed of more than one RawMaterial (denoted with the ) and must be composedof at least one Raw Material.

    A Raw Material can be used to create more than one

    Concrete Type (denoted with the ) but is notrequired to be used to create any Concrete Type.

    A Raw Material must be provided by one Supplier(denoted with the first |) denoted with the first |) andcan only be provided by one Supplier (denoted with thesecond |).

    A Supplier may not provide any Raw Material (denotedwith the 0) but may provide more than one Material .

  • 8/3/2019 Db Design Clc

    11/25

    Dr Tran Thi Song Minh National Economics University

    How to create an IntersectionRelation

    1. Create a new E-R diagram (showing no cardinality) with theoriginal two relations on each end and a new one (theintersection relation) in the middle.

    2. Underneath the intersection relation, write down some of thecomposite primary keys (these will be composed of theprimary keys from the other two relations)

    3. Create a meaningfull name (e.g., Bill of Material) for theintersection relation.

    4. Move the minimum cardinality appearing next to the leftrelation just to the right of the intersection relation.

    5. Move the minimum cardinality appearing next to the rightrelation just to the left of the intersection relation.

    6. The maximum cardinality on both side of the intersectionrelation will always be many7. As a general rule, the new minimum and maximum

    cardinalities for the two original relations will be the one andone.

  • 8/3/2019 Db Design Clc

    12/25

    Dr Tran Thi Song Minh National Economics University

    THE COMPLETED E-R-D FOR THESUPLY CHAIN MANAGEMENT

    CONCRETE TYPE

    RAW MATERIAL

    SUPPLIER

    provides a

    is used for

    BILL OF MATERIAL

    is composed of

  • 8/3/2019 Db Design Clc

    13/25

    Dr Tran Thi Song Minh National Economics University

    READING THE ERD DIAGRAM

    Concrete Type-Bill of Material From left to right: A Concrete Type can have multiple listings of Raw

    Material in Bill of Material and must have a listing of Raw Material in Billof Material.

    From right to left : A Concrete Type found in Bill of Material must befound and can be found only one time in Concrete Type.

    Raw Material-Bill of Material From left to right: A Raw Material can be found in many Bill of Material

    listings but may not be found in any Bill of Material listing. From right to left : A Raw Material found in Bill of Material must be

    found and can be found only one time in Raw Material.

    Supplier-Raw Material From left to right: A Supplier may not provide any Raw Material

    (denoted with the 0) but may provide more than one Material.

    From right to left: A Raw Material must be provided by one Supplier(denoted with the first |) and can only be provided by one Supplier(denoted with the second |).

  • 8/3/2019 Db Design Clc

    14/25

    Dr Tran Thi Song Minh National Economics University

    STEP 3:Defining information(fields) for each relation

    Goal

    To make sure that the information ineach relation indeed in the correct

    relation and that the information can notbe derived from other information.

    Technique

    Three rules of normalization

  • 8/3/2019 Db Design Clc

    15/25

    Dr Tran Thi Song Minh National Economics University

    A FIRST LOOK AT THE RELATIONS FOR THESUPPLY CHAIN MANAGEMENT SIDE OFSOLOMONS DATABASE

    CONCRETE TYPES RELATION (Concrete type, Type name, RawMaterial Total)

    RAW MATERIAL RELATION (Raw Material ID, Raw MaterialName, QOH, Supplier ID, Supplier Name)

    SUPPLIER RELATION (Supplier ID, Supplier Name)

    BILL OF MATERIAL RELATION (Concrete Type, Raw MaterialID, Unit)

  • 8/3/2019 Db Design Clc

    16/25

  • 8/3/2019 Db Design Clc

    17/25

    Dr Tran Thi Song Minh National Economics University

    STEP 4: Using a data definition

    language to create your database.

    Goal

    To take the structure you created in steps 1through 3 and use a data definition

    language to actually create the relations.Tool

    A Database Management System (MS-Access, Visual FoxPro etc.)

    To specify the logical organization for a database

    To access and use the information within thedatabase.

  • 8/3/2019 Db Design Clc

    18/25

    Dr Tran Thi Song Minh National Economics University

    EXERCISES FOR ENTITYRELATIONSHIP DIAGRAMMING

    Define the cardinality among thefollowing entity classes

    Seminar Section

    Seminar

    Qualified Teacher

    Student

    has

    teaches

    Enrolls in

  • 8/3/2019 Db Design Clc

    19/25

    Dr Tran Thi Song Minh National Economics University

    YOUR TASK

    Create the numerical relationships by addingthe symbols of |, O, and crows foot in theappropriate places

    Provide a narrative description of eachnumerical relationship:

    Relationship Narrative Description

    Seminar-Seminar Section

    Seminar-Seminar Section

    Qualified Teacher-Seminar Section

    Seminar Section-Qualified Teacher

    Student-Seminar

    Seminar-Student

  • 8/3/2019 Db Design Clc

    20/25

    Dr Tran Thi Song Minh National Economics University

    EXAMPLES OF NORMALIZATION

    Normalization An important technique to designdatabases

    The process of creating small, stable, yet flexibleand adaptive data structures from complex groupsof data.

    An unnormalizedrelation/ table for concretetypes

    Concretetype ConcreteName RawMaterialTotal

    RawMaterialID

    RawMaterialName

    QOH Unit SupplierName SupplierID

  • 8/3/2019 Db Design Clc

    21/25

    Dr Tran Thi Song Minh National Economics University

    Normalization process

    First Normal Form (1.NF)

    No repeating sections in the table.

    Second Normal Form 2.NF Each nonkey column depends on the whole

    key/ entire key.

    Third Normal Form 3.NF

    Each nonkey column depends nothing butthe key.

  • 8/3/2019 Db Design Clc

    22/25

    Dr Tran Thi Song Minh National Economics University

    Normalization process

    Problem: (Raw Material Total, Raw Material ID, Raw Material Name, QOH, Unit, SupplierName, Supplier ID) is repeated in the unnormalized relation/ table.

    First Normal Form: To split out all repeating sections.

    CONCRETE TYPES (Concrete type Id, concrete name, Raw material total)

    Bill of material (Concrete type Id, Raw Material ID, Raw Material Name, QOH, Unit,Supplier Name, Supplier ID)

    The old key included in the new table toconnect the tables back together

  • 8/3/2019 Db Design Clc

    23/25

    Dr Tran Thi Song Minh National Economics University

    Normalization process

    Problem: Every time we enter the Raw Material Id, we have to reenter Raw Material Name, QOH,Supplier Id, Supplier Name)

    Second Normal Form: To split the table so that all nonkey columns depend on the whole key (notjust part of it)

    Bill of material (Concrete type Id, Raw Material ID, Raw Material Name, QOH, Unit,Supplier Name, Supplier ID)

    Bill of material (Concrete type Id, Raw Material ID, Unit)

    Raw Material (Raw Material ID, Raw Material Name, QOH, Supplier ID, Supplier Name)

    The old key included in the new table to

    connect the tables back together

  • 8/3/2019 Db Design Clc

    24/25

    Dr Tran Thi Song Minh National Economics University

    Normalization process

    Problem: Supplier_Name andSupplier_Address depend on thenonkey column Supplier_Number

    Third Normal Form: To split the table so that every nonkey columndepends nothing but the key

    Raw Material (Raw Material ID, Raw Material Name, QOH,Supplier ID, Supplier Name)

    Raw Material (Raw Material ID, Raw Material Name, QOH,Supplier ID)

    SUPPLIER(Supplier Id, Supplier Name)

    The old key included in the new table toconnect the tables back together

  • 8/3/2019 Db Design Clc

    25/25

    Dr Tran Thi Song Minh National Economics University

    Data Structure Diagram (DSD)

    SUPPLIER

    Supplier Id(PK)

    Supplier Name

    RAW MATERIAL

    Raw material Id(PK)

    Raw material nameQOH

    Supplier Id

    BILL OF MATERIAL

    Raw material Id

    Concrete Type Id

    Unit

    CONCRETE TYPES

    Concrete Type Id(PK)

    Type name

    Total Raw material