Professional Documents
Culture Documents
member
is a member of
Employee Employee number First name Last name Employee function Employee salary
subcontract
staffed by
is assigned to
Project Project number Project name Project label Start date End date
Task
Task name Task cost
contains
References
Data Modeling and Database Design 1. Batini, Ceri, Navathe, Conceptual Database Design, Redwood City, CA: The Benjamin/Cummings Publishing Company, Inc., 1992. 2. Teorey, T. J., Database Modeling and Design: The Entity-Relationship Approach, Morgan Kaufmann Publishers, Inc., 1990. 3. Thomas A. Bruce, Designing Quality Databases with IDEF1X Information Models, Dorset House Publishing, NY: New York, 1991. 4. Texas Instruments, A Guide to IE Using IEF, 2nd edition, Part No. 2739756-0001, 1990. 5. Martin, James, Information Engineering Book II: Planning and Analysis, Prentice-Hall Inc., 1989. 6. Dave Ensor, Ian Stevenson, Oracle Design, O'Reilly & Associates, 1997 7. Rob Gillette, etc., Physical Database Design for Sybase SQL Server, Prentice Hall, 1995. 8. Ralph Kimball, The Data Warehouse Toolkit, Wiley, 1996. JAD References 1. August, J. H.. Joint Application Design: The Group Session Approach to System Design. Englewood Cliffs, NY, Prentice Hall, Inc., 1991. 2. Wood, J. and Silver, D. Joint Application Design: How to Design Quality Systems in 40% Less Time. New York, NY, John Wiley & Sons, 1989. 3. Andrews, D. C. and Leventhal, N. S., Fusion: Integrating IE, CASE, and JAD: A Handbook for Reengineering the Systems Organization, Englewood Cliffs, NJ: Yourdon Press, 1993.
Minder Chen, 1993~2002 Data Modeling - 3 -
Systems Development Life Cycle (SDLC) in a Client/Server Environment Introduction to Data Modeling Database Development Life Cycle Overview
Data Modeling - 4 -
ER modeling technique is the major data modeling method in Information Engineering and is widely supported by most of CASE tools. Data modeling is the foundation of most database-centered transaction processing systems and data warehouse systems
Minder Chen, 1993~2002 Data Modeling - 6 -
RE-ENGINEER business process & systems RE-DESIGN current systems RE-HOST current systems RE-IMAGE current systems
Data Modeling - 7 -
LOW
Minder Chen, 1993~2002
Data Space
Client
Presentation logic Local input validation Output production logic Local peripheral drivers Performance critical processing
Server
Functions that access data on the server Functions that need input from multiple users Functions that coordinate the work of several user
Issues:
Minder Chen, 1993~2002
Distribution of data Platform-specific capabilities and interoperability Connectivity capabilities/platform Frequency of change to codes Configuration management
Data Modeling - 8 -
Application Logic
Process Flow
Programs, Procedures
Data Model
Tables, Indexes
Source: David Vaskevitch, Client/Server Strategies, IDG Books, 1993. Data Modeling - 9 Minder Chen, 1993~2002
Processes Behavior
Architecture
Conceptual (Enterprise) DB Schema Logical DB Design A logical DB schema is a description of the structure of the database that can be processed by a DBMS: relational, network, or hierarchical. A physical DB schema is a description of the implementation of the database in external memory; it describes the storage structures and access methods used in order to effectively access and maintain data.
Logical DB Schema
Physical DB Design
Physical DB Schema
Source: Batini, C., Ceri, S., and Navathe, S. B., Conceptual Database Design: An EntityRelationship Approach, The Benjamin/Cummings Publishing Company, Inc., 1992. Data Modeling - 11 Minder Chen, 1993~2002
Multiple Perspectives
We use this data
ONE BUSINESS
We do these things
DATA
ACTIVITY
HIRE EMPLOYEE
PAY EMPLOYEE
FIRE EMPLOYEE
Data Modeling - 12 -
Member
Agreement
sells; is sold on
generates; generated by
Product
Promotion
sponsors; is sponsored by
Club
Data Modeling - 13 -
Subject Area and Subject Area Diagram Entity Types Entity Instances Finding Entity Types Evaluating Entity Types
Data Modeling - 14 -
Project
Minder Chen, 1993~2002 Data Modeling - 15 -
Customers
Products Orders
Sales-persons Buyers
Legends
: Subject Area
: Association
Minder Chen, 1993~2002 Data Modeling - 16 -
Entity Types
Definition:
An entity is an object or event, real or abstract, about which we would like to store data. Entity is the abbreviation of entity type. It represent a set of entity instances which can be described by the same set of attribute types. The value of the same attribute for each entity instance may be different.
Examples
Customer, Customer Order, Product, Hourly Employee, Project, Department, Unfilled Customer Order
Be clear and concise Avoid abbreviation Be consist with users terminology Identify synonyms
Customer Product Supplier Teacher Client
Use one name as the official name and document others as aliases
Minder Chen, 1993~2002 Data Modeling - 18 -
Data Modeling - 19 -
Properties of Entity Types Name Description Identifier Properties: Estimated number (Max., Min., Average) of entity instances Expected growth rate of entity instances Subject Area in which the Entity Type resides Attributes that describe the Entity Types Examples of entity type instances
Data Modeling - 20 -
Definition of an Entity Type A poor definition of Customer: Anyone that buys something from the company.
Can employees be a customer? Can a leasor be a customer? If the company sold a subsidiary to another company, does the new owner consider a customer?
Good Definition
Compatible
Customer: An ORGANIZATION that purchase PRODUCTs for personal use. Distributor: An ORGANIZATION that purchase PRODUCTs for resale.
Precision:
With appropriate qualifiers Example: An ORGANIZATION is considered to have purchase a PRODUCT when we receive a valid PURCHASE ORDER from it.
Complete
ORGANIZATION, PRODUCT, PURCHASE ORDER need to be defined.
Entity Type
Customer Product Raw-material Supplier Buyer
Description
Information about all persons or organizations who purchases
All goods manufactured and sold Components used to manufacture Products. Vendors of Raw Materials.
Company personnel responsible for purchasing Raw-Materials from Suppliers
Data Modeling - 23 -
Entity Type and Entity Instance (Occurrence) Entity Types Vendor Employee Course Department Entity Instance ABC Co. John Smith Intro. to IE
Marketing Department
Data Modeling - 24 -
Maryland Organization Unit Customer President Bill Clinton Department of Commerce Address
Data Modeling - 25 -
Finding Entity Types Interviews with users JAD workshops Business forms Reports Computer files using reverse engineering Operation manuals
Data Modeling - 26 -
Resources
Any resources that an organization needs to manage should be represented as an Entity Type. Information assists the efficient and effective use of other resources through improved decision. Examples: Inventory, Machine, Bank Account, and Customer.
Roles Played
Roles can be played by persons or organizational units. Examples: Customers, Managers, and Account representatives.
Events
Events are incidents that occur at points in time. An event often involved an interaction between two Entity Types or an action that changes the status of an Entity Type. Examples: Sale, Delivery, and Registration of a motor vehicle.
Minder Chen, 1993~2002 Data Modeling - 27 -
BIAIT:
Analysis of Orders Ordered entities can be a thing, a space, or a skill. View the order from supplier side. If an organization receives no orders, it has no reason for existing. An organization unit can receive multiple types of orders. 4 questions about the Supplier:
Billing (Cash)? Deliver Late (Immediate)? Profile customer? Negotiate price (Fixed)?
Relationships Entity Relationship Diagramming Notation Attributes Identifiers Partitioning and Entity Subtypes
Data Modeling - 30 -
Relationship (Type)
Definition
A Relationship Type is an association among Entity Types. It indicates that there is a business relationship between these Entity Types. Relationship Membership is the participation of an Entity Type in a Relationship. In IE, a Relationship Type can involve only two Entity Types (binary relationship). Some other modeling techniques allow n-ary relationships.
Examples
CUSTOMER places ORDER ORDER is placed by CUSTOMER EMPLOYEE works on PROJECT PROJECT has project member EMPLOYEE
Data Modeling - 31 -
Entity Instance
Student#1 Student#2
Course#A Course#B Course#C Course#D
Course
Relationship
Student takes Course
Minder Chen, 1993~2002
Relationship Paring
Student#1 takes Course#A Student#1 takes Course#B Student#1 takes Course#D Student#2 takes Course#A Student#2 takes Course#C Student#2 takes Course#D
Data Modeling - 32 -
Definition: A collection of pairings of a Relationship Membership in which an Entity Instance is involved. Examples:
Student#1 takes Course#A, #B, and #D Student#2 takes Course#A, #C, and #D Course#A is taken by Student#1 and Student#2
Data Modeling - 33 -
Relationship Cardinality
One-to-One
1:1
E1
E2
One-to-Many
1:M
E1
E2
Many-to-Many
M:N
E1
E2
Data Modeling - 34 -
Relationship Cardinality
The number of Entity Instances involved in the Relationship Instances Grouping in a Relationship Type. Three Forms of Cardinality
1. One-to-one (1:1) DEPARTMENT has MANAGER Each DEPARTMENT has one and only one MANAGER Each MANAGER manages one and only one DEPARTMENT 2. One-to-many (1:m) CUSTOMER places ORDER Each CUSTOMER sometimes (95%) place one or more ORDERs Each ORDER always is placed by exactly one CUSTOMER 3. Many-to-many (m:n) INSTRUCTOR teaches COURSE Each INSTRUCTION teaches zero, one, or more COURSEs Each COURSE is taught by one or more INSTRUCTORs
Data Modeling - 35 -
Cardinality indicator
relationship-description
Entity-X
reversed-relation-description
Entity-Y
Manager
Data Modeling - 36 -
Optionality of Relationship Memberships Whether all entity instances of both entity types need to participate in relationship pairing. Optionality:
Mandatory Optional
Example:
CUSTOMER membership is optional ORDER membership is mandatory
places
CUSTOMER
Minder Chen, 1993~2002
is placed by
ORDER
Data Modeling - 37 -
Relationship Statements
Cardinality indicator
Graphical Notations one one or more
places
CUSTOMER
is placed by
ORDER
zero (sometimes) one (always)
Optionality indicator
Each Entity X optionality relationship cardinality Entity Y Each CUSTOMER sometimes places one or more ORDER. Each ORDER always is placed by one CUSTOMER.
Data Modeling - 38 -
Product
(b)
Parallel Relationship
Part
contained-in
Data Modeling - 40 -
Order
belongs-to
Alternative Notations: Customer places belongs-to Order places 1 belongs-to Order places M Order
Customer
Customer
Data Modeling - 41 -
Identifying Relationships
Association between entity types Entity types that are used on the same forms or documents. A description in a business document that has a verb that relates two entity types
has consists of uses
Minder Chen, 1993~2002 Data Modeling - 42 -
Attributes
Definition
Characteristics that could be used to describe Entity Types and Relationship Types. However, in IE, relationship types are not allowed to have attributes.
Naming Conventions:
Names that have business meaning Don't use abbreviation or possessive case, e.g., PN and Customer's name Don't include entity type name because IEF will prefix the attribute name with entity type name automatically Use standard format: Entity Type Name (Qualifiers) Domain Name Customer Name Employee Starting Date
Examples
Customer has customer name, address, and telephone number Product has quantity-on-hand, weight, volume, color, and name. Employee has SSN, salary, and birthday. Employee-works-for-project has percentage-of-time, starting-date.
Data Modeling - 43 -
Attributes: Notations
Student
Student ID Student Name
Employee Employee number First name Last name Employee function Employee salary
Student studentID
name phone
Attribute Value
Definition
Attribute Values are instances of Attributes used to describe specific Entity Instances
Examples
Customer Number: 011334 Customer Name: Minder Chen State: VA Order Total: $23,000 Sale tax: $250
An attribute of an entity type should have only one value at any given time. (No repeating group) Avoid using complex coding scheme for an attribute. For example: PART Number: X-XXX-XXX
Part Type
Minder Chen, 1993~2002
Material
Sequence Number
Data Modeling - 45 -
Data Modeling - 46 -
Derived
Definition: The Attribute Value can be calculated or deduced from relationship Groupings or from the values of other Attributes. The value of a Derived Attribute changes constantly. Examples: Student Age, Account Balance, Number of courses taken.
Designed
Definition: The Attribute is created to overcome the system constraints. The value of a Designed Attribute does not change. Examples: Student ID, Course number.
Minder Chen, 1993~2002 Data Modeling - 47 -
Data Types
Data Modeling - 48 -
Properties of Attributes
Name Description Attribute Source Category: Basic, Derived, Designed Domain or data type: Text, Number, Date, Time, Timestamp Optionality: Mandatory or optional Length and/or precision Permitted Values (Legal Values)
Ranges A set of values (Code Table)
Tools such as PowerBuilder has additional properties for tables columns called extended attributes
Validation Rule Editing Format Reporting Format
Minder Chen, 1993~2002
Composite Attribute
Definition: Example:
Telephone Number =
Area code + Exchange + Extension There is no support of composite attribute type most of CASE tools. In such case, an composite attribute must be stored as an entity type.
Data Modeling - 50 -
Domain
A collection of values which can be taken by one or more attributes. Date is the domain for Ordered Date, Student's Birthday, Employee Starting Date. A used defined domain can have customized validation rules and formats. CASE tools such as IEF only supports the following basic domains:
Text Number Date Time Timestamp
Data Modeling - 51 -
Identifiers The identifier of an entity type is a set of attributes and/or relationships whose values can uniquely identify an entity. Entity types should have one identifier. Identifiers may consist of
A single attribute: Student ID A set of attributes: Students ID + Course ID An attribute and a relationship membership (implemented as a foreign Key): Order Item No + Order Has Order Item
Data Modeling - 52 -
Identifying Relationship
customer
places
product
Symbol for Identifying Relationship
is ordered by
ORDERS
is placed by contains has
order
is part of
order item
Data Modeling - 53 -
"Jack Smith catches a cold and what he suspects is a flu virus. He makes an appointment with his family doctor who confirm his diagnosis. The doctor prescribes an antibiotic and nasal decongestant tablets. Jack leaves the doctor's office and drives to his local drug store. The pharmacist packages the medication and types the labels for pill bottles. The label includes information about customer, the doctor who prescribe the drug, the drug (e.g., Penicillin), when to take it, and how often, the content of the pill (250 mg), the number of refills, expiration date, and the date of purchase."
Please develop a data model for the entities and relationships within the context of pharmacy. Also develop a definition for "prescription". List all your underlying assumptions used in your data models.
Minder Chen, 1993~2002 Data Modeling - 54 -
Burger World Distribution Center serves as a supplier to 45 Burger World franchises. You are involved with a project to build a database system for distribution. Each franchise submits a day-by-day projection of sales for each of Burger World's menu products - the products listed on the menu at each restaurant - for the coming month. All menu product require ingredients and/or packaging items. Based on projected sales for the store, the system must generate a day-by-day and ingredients need and then collapse those needs into one-per-week purchase requisitions and shipments.
Minder Chen, 1993~2002 Data Modeling - 55 -
Find/Create identifiers for each entity type Add attributes to the entity type in the data model Analyze and revise the data model
Data Modeling - 56 -
Characteristics of Partitioning
Optionality:
Mandatory: Every Entity instances of the Entity Type must fall into one of the Subtype categories. Optional: Not every Entity instances of the Entity Type must fall into one of the Subtype categories.
Entity Life Cycle: The states through which an Entity Type can pass are used for Partitioning. Enumeration:
Fully enumerated Not fully enumerated
Employee
Type
Lecturer Staff
Teaches
Seminar
Status
Wage Hourly
Minder Chen, 1993~2002 Data Modeling - 59 -
PowerDesigner
employee type
Savings Rate
Checking Fees
Data Modeling - 60 -
Data Modeling - 61 -
Normalization
A data base is a model or an image of the reality. Logical Data Base Design is a process of modeling and capturing the end-user views of an application domain and synthesis them into a data base structure. Normalization is a logical data base design method. The basis for normalization is the functional dependencies among attributes in a table.
Minder Chen, 1993~2002 Data Modeling - 62 -
SQL Terminology
Column
Product Table
p_no 101 Row 201 202 product_name Color TV B&W TV PC quantity 24 10 5 price 500 250 2000
CREATE TABLES (p_no CHAR(5) NOT NULL, product_name CHAR(20), quantity SMALLINT, price DECIMAL(10, 2));
Minder Chen, 1993~2002 Data Modeling - 63 -
SQL Terminology
Set Theory Relation Attribute Relational DB Table Column File File Data item Example Product_table Product_name
Tuple
Domain
Row
Pool of legal values
Record
Data type
Product_101's info.
DATE
Data Modeling - 64 -
SQL Principles
The result of a SQL query is always a table (View or Dynamic Table) Rows in a table are considered to be unordered Dominate the markets since late 1980s Can be used in interactive programming environments Provide both data definition language (DDL) and data manipulation language (DML) A non-procedural language Can be embedded in 3GL:
Embedded SQL Dynamic SQL
Minder Chen, 1993~2002 Data Modeling - 65 -
ALTER
TABLE
Data Modeling - 66 -
SQL: Introduction
A relational data base is perceived by its users as a collection of tables E. F. Codd 1969
Most CASE products support the development of relational data base centered applications
Minder Chen, 1993~2002 Data Modeling - 67 -
Data Modeling - 68 -
Database Table
The following code retrieves only the Last Name and the Employee ID where the Employee ID is greater than 5. The records are retrieved in descending order.
SELECT LastName, EmployeeID FROM Employees WHERE EmployeeID > 5 ORDER BY EmployeeID DESC
Data Modeling - 69 -
WHERE Clause
WHERE: Use the Where clause to limit the selection. The # symbol indicates literal date values. SELECT * FROM Employees WHERE LastName = "Smith" SELECT Employees.LastName FROM Employees WHERE Employees.State in ('NY','WA') SELECT OrderID FROM Orders WHERE OrderDate BETWEEN #01/01/93# AND #01/31/93#
Minder Chen, 1993~2002 Data Modeling - 70 -
Keys
A key, also called identifier, is an Attribute or a Composite Attribute that can be used to uniquely identify an instance of an entity type. Examples: Entity Type Key
Warehouse Product Student Ship Stock of Product Warehouse Number Product Number Student ID or SSN Name and Port of Registration Product Number and Warehouse No.
Data Modeling - 71 -
Types of Key
Primary Key: A unique key is an attribute or a set of attributes that has been used by the DBMS as the identifier of a table. Candidate (Alternative) Key: An attribute or a set of attributes that could have been used as the primary key of a table. Secondary (Index) Key: An attribute or a set of attributes that has been used to construct the data retrieval index. Concatenated (Combined or Composite) Key: A set of attributes that has been used as the key. Foreign Key: An attribute or a set of attributes that is used as the primary key in another table.
Minder Chen, 1993~2002 Data Modeling - 72 -
Purposes of Normalization
Avoid maintenance problems such as Update . Insert: There may be no place to insert new information. Delete: Some important information will be lost by deletion. Update: Inconsistency may occur because of the existence of data redundancy. Provide maximum flexibility to meet future information needs by keeping tables corresponding to object types in their simplified forms.
Minder Chen, 1993~2002 Data Modeling - 73 -
Don't rush to put all the information in one table. Create a table to correspond to a class of a simple object type that should exist by itself, i.e., "one fact in one place." Include common fields (links) as ways of joining information from several related tables. Avoid redundancy by using links to retrieve data from related tables.
Data Modeling - 74 -
Normalization Theory
Normalization is a process of systematically breaking a complex table into simpler ones. It is built around the concept of normal forms. A relation is in a particular normal form if it satisfies a specific set of constraints such as dependencies among attributes in the relation. For x is an integer and x > 1, if a relation is in x-NF than it is in (x-1)-NF. Higher order normal forms are usually more desirable than lower order normal forms. Normalization process usually starts from complex relations which are usually drawn from some existing documents such as business forms.
Minder Chen, 1993~2002 Data Modeling - 75 -
A Business Form
Data Modeling - 76 -
Solution
Unnormalized table
(OrderNo, OrderDate, CustNo, CustAddress, CustType, Tax, Total, 1{ProductNo, Description, Quantity, UnitPrice,Subtotal}n)
1st NF
Remove partial FD
2nd NF
Remove transitive FD
3rd NF
Minder Chen, 1993~2002
Unnormalized Form
A relation that has multi-valued attributes (repeating groups). Normalization Process: Remove Multi-value Attributes If an unnormalized relation R has a primary key K and a multi-value attribute M, the normalization process is:
The multi-value attribute M should be removed from R. A new relation will be created with (K,M) as the primary key of the relation. There may be some other attributes associated with this new relation. R will then be at least in 1NF.
Example: An Employee relation has an attribute language-spoken. For some employees there may be more than one language that they can speak.
EMP (employeeID, empName, empAddress, (language1, language2, ...)) EMP (employeeID, empName, empAddress) EMP-LANGUAGE (employeeID, language, skillLevel)
Minder Chen, 1993~2002 Data Modeling - 79 -
Data Modeling - 80 -
Functional Dependency
Notation: R.X => R.Y Definition: Attribute Y of Relation R is functionally dependent on the Attribute X of Relation R when there is each value of R.Y associated with no more than one value of R.X. R.X and R.Y may be composite attributes. Description:
R .Y is functionally dependent on R.X R.X functionally determines R.Y
Minder Chen, 1993~2002 Data Modeling - 81 -
R.A => R.B If B is not functionally dependent on any subset of A (other than A itself), B is fully dependent on A in R. If B is functionally dependent on a subset of A (other than A itself), B is partially dependent on A in R.
Data Modeling - 82 -
Example
Supplier-Part relation has attributes supplier#, part#, qty, city, distance, where (supplier#, part#) is the key. City is partially dependent on supplier#. SUPPLIER-PART (supplier#, part#, qty, city, distance) SUPPLIER-PART (supplier#, Part#, qty) SUPPLIER (supplier#, city, distance)
Minder Chen, 1993~2002 Data Modeling - 83 -
Non-loss Decomposition
Normalization is a reduction (decomposition) process that replaces a relation by suitable projections. Each of the projection is a new relation that is in a further normalized form than the original relation. The collection of projections is equivalent to the original relation. The original relation can always be recovered by taking the natural join of these projections. Any information that can be derived from the original relation can also be derived from the further normalized relations. The converse is not true. The process is reversible because no information is loss in the reduction process.
Minder Chen, 1993~2002 Data Modeling - 84 -
Transitive Dependency
In a relation R, if R.A =>R.B and R.B => R.C then attribute C is said to be transitively dependent on attribute A.
Data Modeling - 85 -
All the non-key attributes have atomic value and dependent on the key (1NF - No multi-value attribute), the whole key, (2NF - No Partially Functional Dependency) and nothing but the key (3NF - No Transitive Functional Dependency)
Minder Chen, 1993~2002 Data Modeling - 87 -
Normalization Process
Unnormalized Form
A
1NF
H
2NF
G F H
3NF
D
B C D
Data Modeling - 88 -
Cons
Many complex queries will be slower because joins have to be performed to retrieve relevant data from several normalized tables Programmers/users have to understand the underlying data model of an database application in order to perform proper joins among several tables The formulation of multiple-level queries is a nontrivial task.
Data Modeling - 89 -
Data Modeling - 90 -
Tables in Relational DB
Identify Primary Keys and Foreign Keys in the following Tables!!!
ID
ID
ID
Data Modeling - 91 -
Join Tables
SELECT Orders.OrderID, Orders.CustID, LastName, Firstname, Orders.ItemID, Description FROM Customer, Orders, Inventory WHERE Customer.CustID = Orders.CustID AND Orders.ItemID = Inventory.ItemID ORDER BY CustID, Orders.ItemID
ID
ID
Data Modeling - 92 -
Data Modeling - 93 -
Data Modeling - 94 -
Denormalization
The process of intentionally backing away from normalization to improve performance. Denormalization should not be the first choice for improving performance and should only be used for fine tuning a database for a particular application. Requirements
Prior normalization Knowledge of data usage
Benefits
Minimize the need for joins Reduce number of tables Reduce number of foreign keys Reduce number of indices How often are two data items needed together How many rows are involved How volatile is denormalized data How important is visibility of data to users What is the minimum response time and frequency of an query
Data Modeling - 95 -
De-normalization: An Example
JOIN
R1
R2
Denormalization
R1 * R 2
Where:
R2
R1 (ProductNo, SupplierNo, Price) R2 (SupplierNo, Name, Address, Phone) R1*R2 (ProductNo, SupplierNo, Name, Address, Phone, Price)
R2 should be kept to prevent data loss. Data redundancy in R1*R2 and R2 could cause potential data inconsistency problems if the redundant data in these two tables are not maintained properly.
Minder Chen, 1993~2002 Data Modeling - 96 -
Data Modeling - 97 -
Isolated Entity Type Solitary Entity Type One-to-One Relationship Redundant Relationship Multi-Valued Attributes Attribute with Attributes Many-to-Many Relationship
Data Modeling - 98 -
Data Modeling - 99 -
Correct
Purchase Order
Redundant Relationship
Is this relationship redundant? has ordered
customer
places
product
is ordered by
ORDERS
is placed by contains has
order
is part of
order item
Redundant Relationship
Redundant Product is held as Stock contains Non-redundant is held in stocks
Warehouse
holds
Product
is contained in contains
Order Line
is contained in contains
Order
contains
Order History
Multi-Valued Attribute
Definition
An Attribute that may have more than one value at a time is called a multi-valued attribute.
Solution:
Example:
Employee(ID, Name, Phone) Employee(111, John Smith, 210-999-8888) Employee_language(ID, Language) Employee_language(111, English) Employee_language(111, Chinese)
Data Modeling - 104 -
Solution:
Create an Entity Type to avoid an Attribute with Attributes. Add new attributes to the existing Entity Type.
Minder Chen, 1993~2002 Data Modeling - 105 -
Order
belongs-to
Product
Why?
There is no place to attach Attributes that are required to describe a many-to-many Relationship. It is difficult to translate many-to-many Relationships into relational tables automatically.
How?
A many-to-many relationship can be decomposed into two one-to-many Relationships by creating an Associative Entity Type between the existing two Entity Types.
contains has
Order
belongs to
Order Line
is contained in
Product
(b)
Student
takes
is-taken-by
Course
(c)
consists-of
Part
is-contained-in
Data Modeling - 108 -
Bills of Material
Part consists-of A
is-a-component-in
2
E D
1
F
Product Structure
B C D E D F
2 1 1 3 2 2
Data Modeling - 109 -
uses Project
supplies Supplier
Minder Chen, 1993~2002 Data Modeling - 110 -
Order
belongs to
Order Line
is contained in
Product
CREATE TABLE ORDER (OrderNo CHAR(10) OrderDate DATE, CustomerID CHAR(10), SalePersonID CHAR(10));
Minder Chen, 1993~2002
NOT NULL,
The entire, or part of, a data (entity-relationship) model can be translated into a normalized database design. Objects Created
At most one relational database One or more relations (tables) Data structures (DDL) representing the elements (attributes) and the primary key of each relation Data type of each data elements
Heuristics of Transformation
A table is created for each Entity Type in the ER diagram. A table is created for each multi-valued attribute. Relationship Types are implemented as tables or as foreign keys in other tables. Many-to-many relationship types are translated into tables. Foreign keys are used for implementing one-to-one and one-to-many Relationship Types. For one-to-many Relationship Types, the foreign key is placed in the table that represents the Entity Type on the "many" end of the Relationship Type. For identifying one-to-many Relationship Types, the PK of the "one" table migrate to the "many" table as a FK and the FK is also part of the PK of the "many" table. For non-identifying one-to-many Relationship Types, the PK of the "one" table migrate to the "many" table as a FK and the FK is a non-key attribute of the "many" table.
Minder Chen, 1993~2002 Data Modeling - 113 -
http://www.powersoft.com/
Data Modeling - 114 -
Target DBMS
Minder Chen, 1993~2002
PowerDesigner
Conceptual Data Model Project : Management Model : Project Management Author : User Version 6.x 7/21/98
Customer Customer number Customer name Customer address Customer activity Customer telephone Customer fax
Is member of supervises Employee Employee number First name Last name Employee function Employee salary Is manager of
Uses
Subcontract
Material Material number Material name Material type Participate Start date End date
composes
composed of
Notations
Employee
Entity
Employee number First name Last name Employee function Employee salary
Relationship
Employ ee Division Division number Division name Division address Employ number ee First name Last name Employ function ee Employ salary ee
One-to-many
Minder Chen, 1993~2002 Data Modeling - 117 -
More on Relationships
Employee Employee number First name Last name Employee function Employee salary is a member of Team Team number Specialty
member
Many-to-many cardinality
A project 'contains one or more tasks, and a task's existence is dependent on the project.
Advanced Concepts
Material Material number Material name Material type
composes composed of
Savings Rate
Subtype
Employee number First name Last name Employee function Employee salary
Reflexive relationship
Define Entities
Define Attributes
Check Parameters
Relationship Definition
Employee Employee number First name Last name Employee function Employee salary
DIVNUM = DIVNUM
Dependent Relationship
Conceptual Data Model Transformation
Physical Data Model
Minder Chen, 1993~2002
PROJECT PRONUM <pk> CUSNUM <fk> EMPNUM <fk> ACTBEG ACTEND PRONAME PROLABL
PRONUM = PRONUM
Physical Data Model Project:Management Model : Project Management Author :User Version6.x 7/21/98
TEANUM = TEANUM
EMPLOYE_MATERIAL MATERIAL.MATNAME char(30) PROJ.EMPLOYEE.EMPNUM numeric(5) PROJ.EMPLOYEE.EMPFNAM char(30) PROJ.EMPLOYEE.EMPLNAM char(30) PROJ.EMPLOYEE.EMPFUNC char(30) MATERIAL PROJ.EMPLOYEE USED
EMPNUM = EMP_EMPNUM
EMPLOYEE EMPNUM <pk> EMP_EMPNUM <fk> DIVNUM <fk> EMPFNAM <ak> EMPLNAM <ak> EMPFUNC <ak> EMPSAL
PROJECT PRONUM <pk> CUSNUM <fk> EMPNUM = EMPNUM EMPNUM <fk> ACTBEG ACTEND PRONAME PROLABL
EMPNUM = EMPNUM
PRONUM = PRONUM
TNUM = CPN_MATNUM
PARTICIPATE PRONUM <pk,fk> PRONUM = PRONUM TSKNAME <pk,fk> TSKNAME = TSKNAME EMPNUM <pk,fk> PARBEG PAREND
Referential Integrity
The arrow is pointing from the table containing the foreign key to the table where the foreign key is used as a primary key.
Deletion Rules
Update Constraints Delete Constraints None Restrict Cascade Set null Set Default
Referential Integrity
alter table PROJ.EMPLOYEE add constraint FK_EMPLOYEE_CHIEF_EMPLOYEE foreign key (EMP_EMPNUM) references PROJ.EMPLOYEE (EMPNUM) / alter table PROJ.EMPLOYEE add constraint FK_EMPLOYEE_BELONGS_T_DIVISION foreign key (DIVNUM) references ADMIN.DIVISION (DIVNUM) / alter table PROJ.PROJECT add constraint FK_PROJECT_SUBCONTRA_CUSTOMER foreign key (CUSNUM) references PROJ.CUSTOMER (CUSNUM) / alter table PROJ.PROJECT add constraint FK_PROJECT_IS_RESPON_EMPLOYEE foreign key (EMPNUM) references PROJ.EMPLOYEE (EMPNUM) / alter table PROJ.TASK add constraint FK_TASK_BELONGS_T_PROJECT foreign key (PRONUM) references PROJ.PROJECT (PRONUM) /
Minder Chen, 1993~2002 Data Modeling - 134 -
Define Keys
Identify Critical Transactions
Add Columns:
Redundant columns Derived data columns
Manipulate Tables:
Collapse tables Supertypes & subtypes
Add Tables:
Derived data tables
Controlling Access
Source: Gillete, Rob, etc., Physical Database Design for Sybase SQL Server, Prentice Hall, 1995.
Manage Objects:
Sizes Placement Data Modeling - 135 -
Summarized
Derived
Detailed Past
Informational Database
Projecte Current d
Operational Database
Current value
Informational Database
Archival data, summarized data, calculated data Subject areas across enterprise Static until refreshed Joined views suitable for business analysis Low - Medium Access only; no direct update Highly unstructured, heuristic or analytical processing Several seconds to minutes
Data Modeling - 137 -
Application by application
Dynamic Fully normalized for transaction processing High Updated on a record and field basis Highly structured transaction processing Sub-second to 2-3 seconds
Response Time
Minder Chen, 1993~2002
Relational View
Multidimensional View
Minder Chen, 1993~2002 Data Modeling - 138 -
Dimensional Model
Product
Key Name Description Size Price
Sale
Product Key Market Key Promotion Key Time Key
Dollars Units Price Cost
Market Region
Key Description District Region Demographics
Time
Key Weekday Holiday Fiscal
Promotion
Key Description Discount Media
Region
Product
Time
Why?
An OLTP (On-Line Transaction Process) design of an order processing system may have dozens or hundreds of tables. It becomes difficult for business managers to understand the design in order to analyze the data.
Data Modeling - 140 -
Product Product identifier <pk> Brand identifier <fk> Product description Product category Product unit price
Customer Customer identifier <pk> Customer name Customer address Customer activity Customer phone number Customer fax number
int char(30) char(80) char(80) char(12) char(12) Year identifier Year name Year <pk> int char(30)
Customer identifier = Customer identifier Year identifier = Year identifier Product identifier = Product identifier
Sale Time identifier Customer identifier Store identifier Product identifier Sale total Sale revenu <fk> <fk> <fk> <fk> int int int int real real
Quarter Quarter identifier <pk> int Year identifier <fk> int Quarter name char(10)
Quarter identifier = Quarter identifier
Month Month identifier <pk> int Quarter identifier <fk> int Month name char(10)
Month identifier = Month identifier
Region Region identifier <pk> int Country identifier <fk> int Region name char(30)
Region identifier = Region identifier
Week Week identifier <pk> int Month identifier <fk> int Week name char(30) Week number in year int
Week identifier = Week identifier
Store Store identifier Region identifier Store name Store address Store manager Store phone number Store FAX number Store financial services type Store photo services type
<pk> int <fk> int char(50) char(80) char(30) char(20) char(20) char(10) char(10)
Day Week identifier <fk> Time identifier <pk> Date Day of week Day number in month
dept_id = parent_id dept dept_id int parent_id int name varchar(255) description text date_changed datetime
pfid = pfid product_variant sku int pfid varchar(30) attribute0 tinyint attribute1 tinyint attribute2 tinyint attribute3 tinyint attribute4 tinyint
product_family pfid varchar(30) dept_id int manufacturer_id int name varchar(255) short_description varchar(255) long_description text image_filename varchar(255) intro_date datetime date_changed datetime list_price int monogramable tinyint
pfid = pfid
shopper sku = sku shopper_id char(32) order_id = order_id created datetime name varchar(235) password varchar(20) street varchar(50) city varchar(50)shopper_id = shopper_id state varchar(30) receipt zip varchar(15) order_id char(26) country varchar(20) shopper_id char(32) phone varchar(16) total int email varchar(50) status tinyint date_entered datetime date_changed datetime marshalled_receipt image shopper_id = shopper_id
receipt_item pfid varchar(30) sku int order_id char(26) row_id int quantity int adjusted_price int promo_price promo_name varchar(255) promo_type int promo_description text promo_rank int active int date_start datetime date_end datetime shopper_all int shopper_column varchar(64) shopper_op varchar(2) shopper_value varchar(64) cond_all int cond_column varchar(64) cond_op varchar(2) cond_value varchar(64) cond_basis char(1) cond_min int award_all int award_column varchar(64) award_op varchar(2) award_value varchar(64) award_max int disjoint_cond_award int disc_type char(1) disc_value realData Modeling
- 146 -
Attribute 0 of pfid 14 is size and the attribute value 1 is Grande and 2 is Tall and 3 is Short
http://www.oracle.com/tools/jdeveloper/documents/jsptwp/index.html?content.html