Sie sind auf Seite 1von 25

4.

3 CREATING A DATABASE ENVIRONMENT

Dr Tran Thi Song Minh National Economics University

KEY TERMS
A Database = a collection of information that you
organize and access according to the logical structure of that information. A relational database = a database that uses a series of 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, or things about which you wish to store information and that you can identify with an unique key (called a primary key) A primary key = A field (or group of fields in some cases) that uniquely describes each record/ an instance. An instance = An occurrence of an entity class that can be uniquely described with a primary key.

Dr Tran Thi Song Minh National Economics University

KEY TERMS (Contd)


A intersection relation/ a composite relation = a relation you create to eliminate a many-to-many relationship. A composite primary key = a primary key that consists of the primary fields from the two intersecting relations. A foreign key = a primary key of one file (relation) that appears in another file (relation).

Dr Tran Thi Song Minh National Economics University

FOUR STEPS IN DESIGNING AND BUILDING A RELATIONAL DATABASE


1. Defining entity classes and primary keys 2. Defining relationships and cardinality among entity classes 3. Defining information (fields) for each relation 4. Using a data definition language to create your database.
Dr Tran Thi Song Minh National Economics University

ENTITY-RELATIONSHIP DIAGRAM SYMBOLS


Entity class Single relationship Multiple relationship

A relationship
Zero or optional relationship

Dr Tran Thi Song Minh National Economics University

A SUPPLY CHAIN MANAGEMENT REPORT FOR SOLOMON ENTERPRISES


SOLOMON ENTERPRISES Supply Report Ending October 14, 2005
CONCRETE
Type
1

RAW MATERIAL
ID
B C A

SUPPLIER
ID
412 444 999

Name
Home

Name
Cement paste Sand Water Total

Unit QOH
1 2 1.5 4.5 1 2 1 Total 4 400 1200 9999 400 1200 9999

Name
Wesley Enterprises Juniper Sand & Gravel N/A

Comm

B C A

Cement paste Sand Water

412 444 999

Wesley Enterprises Juniper Sand & Gravel N/A

Dr Tran Thi Song Minh National Economics University

BUSINESS RULES
1. A given concrete type will have many raw materials 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 in its database that doesnt currently provide any raw materials.
Dr Tran Thi Song Minh National Economics University

STEP 1: Defining entity classes and primary keys


Goal

To define the various entity classes and the primary keys that uniquely define each record or instance within each entity class.

Entity classes
Concrete Type Raw Material Supplier

Primary Key
Concrete Type (ID) Raw Material ID Suppler ID

Dr Tran Thi Song Minh National Economics University

STEP 2: Defining relationships among entity classes


Goal

To define the relationships among the entity classes. is composed of


CONCRETE TYPE
An Intersection Relation should be created to remove this many-tomany relationship

RAW MATERIAL

provides a SUPPLIER
Dr Tran Thi Song Minh National Economics University

READING THE Entity-Relationship DIAGRAM


A Concrete Type is composed of more than one Raw Material (denoted with the ) and must be composed of at least one Raw Material. A Raw Material can be used to create more than one Concrete Type (denoted with the ) but is not required 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 |) and can only be provided by one Supplier (denoted with the second |). A Supplier may not provide any Raw Material (denoted with the 0) but may provide more than one Material .

Dr Tran Thi Song Minh National Economics University

How to create an Intersection Relation


1. 2. 3. 4. 5. 6. 7. Create a new E-R diagram (showing no cardinality) with the original two relations on each end and a new one (the intersection relation) in the middle. Underneath the intersection relation, write down some of the composite primary keys (these will be composed of the primary keys from the other two relations) Create a meaningfull name (e.g., Bill of Material) for the intersection relation. Move the minimum cardinality appearing next to the left relation just to the right of the intersection relation. Move the minimum cardinality appearing next to the right relation just to the left of the intersection relation. The maximum cardinality on both side of the intersection relation will always be many As a general rule, the new minimum and maximum cardinalities for the two original relations will be the one and one.
Dr Tran Thi Song Minh National Economics University

THE COMPLETED E-R-D FOR THE SUPLY CHAIN MANAGEMENT


is composed of CONCRETE TYPE

is used for BILL OF MATERIAL RAW MATERIAL

provides a SUPPLIER
Dr Tran Thi Song Minh National Economics University

READING THE ERD DIAGRAM


Concrete Type-Bill of Material

Raw Material-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 Bill of Material. From right to left : A Concrete Type found in Bill of Material must be found and can be found only one time in Concrete Type.
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. 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 |).

Supplier-Raw Material

Dr Tran Thi Song Minh National Economics University

STEP 3:Defining information (fields) for each relation


Goal
To make sure that the information in each relation indeed in the correct relation and that the information can not be derived from other information.

Technique
Three rules of normalization

Dr Tran Thi Song Minh National Economics University

A FIRST LOOK AT THE RELATIONS FOR THE SUPPLY CHAIN MANAGEMENT SIDE OF SOLOMONS DATABASE
CONCRETE TYPES RELATION (Concrete type, Type name, Raw
Material Total)

RAW MATERIAL RELATION (Raw Material ID,


Name, QOH, Supplier ID, Supplier Name)

Raw Material

SUPPLIER RELATION (Supplier ID, Supplier Name) BILL OF MATERIAL RELATION (Concrete Type,
ID, Unit)
Raw Material

Dr Tran Thi Song Minh National Economics University

The correct structure of the Supply Chain management Side of Solomons Database
CONCRETE TYPES RELATION (Concrete type, Type Description,
Raw Material Total)

RAW MATERIAL RELATION (Raw Material ID,


Name, QOH, Supplier ID)

Raw Material

SUPPLIER RELATION (Supplier ID, Supplier Name) BILL OF MATERIAL RELATION (Concrete Type,
ID, Unit)
Raw Material

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 1 through 3 and use a data definition language to actually create the relations. Tool A Database Management System (MSAccess, Visual FoxPro etc.)
To specify the logical organization for a database To access and use the information within the database.
Dr Tran Thi Song Minh National Economics University

EXERCISES FOR ENTITY RELATIONSHIP DIAGRAMMING


Define the cardinality among the following entity classes
has Seminar

Qualified Teacher

teaches Seminar Section

Enrolls in
Student

Dr Tran Thi Song Minh National Economics University

YOUR TASK
Create the numerical relationships by adding the symbols of |, O, and crows foot in the appropriate places Provide a narrative description of each numerical relationship:
Relationship
Seminar-Seminar Section Seminar-Seminar Section

Narrative Description

Qualified Teacher-Seminar Section


Seminar Section-Qualified Teacher Student-Seminar Seminar-Student
Dr Tran Thi Song Minh National Economics University

EXAMPLES OF NORMALIZATION
Normalization An important technique to design databases The process of creating small, stable, yet flexible and adaptive data structures from complex groups of data.

An unnormalized relation/ table for concrete types


Concrete type Concrete Name Raw Material Total Raw Material ID Raw Material Name QOH Unit Supplier Name Supplier ID

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 but the key.

Dr Tran Thi Song Minh National Economics University

Normalization process
Problem: (Raw Material Total, Raw Material ID, Raw Material Name, QOH, Unit, Supplier Name, 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)

The old key included in the new table to connect the tables back together

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

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 (not just 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)


The old key included in the new table to connect the tables back together

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

Dr Tran Thi Song Minh National Economics University

Normalization process
Problem: Supplier_Name and Supplier_Address depend on the nonkey column Supplier_Number Third Normal Form: To split the table so that every nonkey column depends 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)
The old key included in the new table to connect the tables back together

SUPPLIER(Supplier Id, Supplier Name)

Dr Tran Thi Song Minh National Economics University

Data Structure Diagram (DSD)


RAW MATERIAL Raw material Id (PK) Raw material name QOH Supplier Id BILL OF MATERIAL Raw material Id Concrete Type Id Unit

SUPPLIER
Supplier Id (PK) Supplier Name CONCRETE TYPES Concrete Type Id (PK) Type name Total Raw material

Dr Tran Thi Song Minh National Economics University

Das könnte Ihnen auch gefallen