Database Systems - Chapter 02.pdf

(1093 KB) Pobierz
C6545_02 6/6/2007 9:18:3 Page 30
2
DATA MODELS
In this chapter, you will learn:
About data modeling and why data models are important
About the basic data-modeling building blocks
What business rules are and how they influence database design
How the major data models evolved
How data models can be classified by level of abstraction
This chapter examines data modeling. Data modeling is the first step in the database design
journey, serving as a bridge between real-world objects and the database that resides in the
computer.
P review
One of the most vexing problems of database design is that designers, programmers, and
end users see data in different ways. Consequently, different views of the same data can lead
to database designs that do not reflect an organization’s actual operation, failing to meet
end-user needs and data efficiency requirements. To avoid such failures, database designers
must obtain a precise description of the nature of the data and of the many uses of that data
within the organization. Communication among database designers, programmers, and end
users should be frequent and clear. Data modeling clarifies such communication by reducing
the complexities of database design to more easily understood abstractions that define
entities and the relations among them.
First, you will learn what some of the basic data-modeling concepts are and how current
data models developed from earlier models. Tracing the development of those database
models will help you understand the database design and implementation issues that are
addressed in the rest of this book. Second, you will be introduced to the Entity Relationship
Diagram (ERD) as a data modeling tool. ER diagrams can be drawn using a variety of
notations.Within this chapter you will be introduced to the traditional Chen notation, the
more current Crows’ Foot notation, and the newer class diagram notation, which is part of
the Unified Modeling Language (UML). Finally, you will learn how various degrees of data
abstraction help reconcile varying views of the same data.
1256015919.486.png 1256015919.497.png 1256015919.508.png 1256015919.519.png 1256015919.001.png
 
C6545_02 6/6/2007 8:54:29 Page 31
31
DATA MODELS
2.1 DATA MODELING AND DATA MODELS
Database design focuses on how the database structure will be used to store and manage end-user data. Data modeling,
the first step in designing a database, refers to the process of creating a specific data model for a determined problem
domain. (A problem domain is a clearly defined area within the real world environment, with well defined scope and
boundaries, that is to be systematically addressed.) A data model is a relatively simple representation, usually
graphical, of more complex real-world data structures. In general terms, a model is an abstraction of a more complex
real-world object or event. A model’s main function is to help you understand the complexities of the real-world
environment. Within the database environment, a data model represents data structures and their characteristics,
relations, constraints, transformations, and other constructs with the purpose of supporting a specific problem domain.
NOTE
The terms
data model
and
database model
are often used interchangeably. In this book, the term
database
model
is used to refer to the implementation of a
data model
in a specific database system.
Data modeling is an iterative, progressive process. You start with a simple understanding of the problem domain, and
as your understanding of the problem domain increases, so does the level of detail of the data model. Done properly,
the final data model is in effect a “blueprint” containing all the instructions to build a database that will meet all end-user
requirements. This blueprint is narrative and graphical in nature, meaning that it contains both text descriptions in
plain, unambiguous language and clear, useful diagrams depicting the main data elements.
NOTE
An implementation-ready data model should contain at least the following components:
A description of the data structure that will store the end-user data.
A set of enforceable rules to guarantee the integrity of the data.
A data manipulation methodology to support the real-world data transformations.
Traditionally, database designers relied on good judgment to help them develop a good data model. Unfortunately,
good judgment is often in the eye of the beholder, and it often develops after much trial and error. For example, if each
of the students in this class has to create a data model for a video store, it’s very likely that each of them will come
up with a different model. Which one would be the correct one? The simple answer is “the one that meets all the
end-user requirements,” and there may be more than one correct solution! Fortunately, database designers make use
of existing data modeling constructs and powerful database design tools that substantially diminish the potential for
errors in database modeling. In the following sections you will learn how existing data models are used to represent
real world data and how the different degrees of data abstraction facilitate data modeling. But first, you must
understand the importance of data models and their basic constructs.
2.2 THE IMPORTANCE OF DATA MODELS
Data models can facilitate interaction among the designer, the applications programmer, and the end user. A
well-developed data model can even foster improved understanding of the organization for which the database design
is developed. In short, data models are a communication tool. This important aspect of data modeling was summed
up neatly by a client whose reaction was as follows: “I created this business, I worked with this business for years, and
this is the first time I’ve really understood how all the pieces really fit together.”
1256015919.022.png 1256015919.033.png 1256015919.044.png 1256015919.055.png 1256015919.066.png 1256015919.077.png 1256015919.088.png 1256015919.099.png 1256015919.110.png 1256015919.121.png 1256015919.132.png 1256015919.143.png 1256015919.153.png 1256015919.164.png 1256015919.175.png 1256015919.186.png 1256015919.197.png 1256015919.208.png 1256015919.219.png 1256015919.230.png 1256015919.241.png 1256015919.252.png 1256015919.263.png 1256015919.274.png 1256015919.285.png 1256015919.296.png 1256015919.307.png 1256015919.318.png 1256015919.329.png 1256015919.340.png 1256015919.351.png 1256015919.362.png 1256015919.373.png 1256015919.384.png 1256015919.395.png 1256015919.406.png 1256015919.417.png 1256015919.428.png 1256015919.439.png 1256015919.450.png 1256015919.461.png 1256015919.472.png 1256015919.480.png 1256015919.481.png 1256015919.482.png 1256015919.483.png 1256015919.484.png 1256015919.485.png 1256015919.487.png 1256015919.488.png 1256015919.489.png 1256015919.490.png 1256015919.491.png 1256015919.492.png 1256015919.493.png 1256015919.494.png 1256015919.495.png 1256015919.496.png 1256015919.498.png 1256015919.499.png 1256015919.500.png 1256015919.501.png 1256015919.502.png 1256015919.503.png 1256015919.504.png 1256015919.505.png 1256015919.506.png 1256015919.507.png 1256015919.509.png 1256015919.510.png 1256015919.511.png 1256015919.512.png 1256015919.513.png 1256015919.514.png 1256015919.515.png 1256015919.516.png 1256015919.517.png 1256015919.518.png 1256015919.520.png 1256015919.521.png 1256015919.522.png 1256015919.523.png 1256015919.524.png 1256015919.525.png 1256015919.526.png 1256015919.527.png 1256015919.528.png 1256015919.529.png 1256015919.002.png 1256015919.003.png 1256015919.004.png 1256015919.005.png 1256015919.006.png 1256015919.007.png 1256015919.008.png 1256015919.009.png 1256015919.010.png 1256015919.011.png 1256015919.012.png 1256015919.013.png 1256015919.014.png 1256015919.015.png 1256015919.016.png 1256015919.017.png 1256015919.018.png 1256015919.019.png 1256015919.020.png 1256015919.021.png 1256015919.023.png 1256015919.024.png 1256015919.025.png 1256015919.026.png 1256015919.027.png 1256015919.028.png 1256015919.029.png 1256015919.030.png 1256015919.031.png 1256015919.032.png 1256015919.034.png 1256015919.035.png 1256015919.036.png 1256015919.037.png 1256015919.038.png 1256015919.039.png 1256015919.040.png 1256015919.041.png 1256015919.042.png 1256015919.043.png 1256015919.045.png 1256015919.046.png 1256015919.047.png 1256015919.048.png 1256015919.049.png 1256015919.050.png 1256015919.051.png 1256015919.052.png 1256015919.053.png 1256015919.054.png 1256015919.056.png 1256015919.057.png 1256015919.058.png 1256015919.059.png 1256015919.060.png 1256015919.061.png 1256015919.062.png 1256015919.063.png 1256015919.064.png 1256015919.065.png 1256015919.067.png 1256015919.068.png 1256015919.069.png 1256015919.070.png 1256015919.071.png 1256015919.072.png 1256015919.073.png 1256015919.074.png 1256015919.075.png 1256015919.076.png 1256015919.078.png 1256015919.079.png 1256015919.080.png 1256015919.081.png 1256015919.082.png 1256015919.083.png 1256015919.084.png 1256015919.085.png 1256015919.086.png 1256015919.087.png 1256015919.089.png 1256015919.090.png 1256015919.091.png 1256015919.092.png 1256015919.093.png 1256015919.094.png 1256015919.095.png 1256015919.096.png 1256015919.097.png 1256015919.098.png 1256015919.100.png 1256015919.101.png 1256015919.102.png 1256015919.103.png 1256015919.104.png 1256015919.105.png 1256015919.106.png 1256015919.107.png 1256015919.108.png 1256015919.109.png 1256015919.111.png 1256015919.112.png 1256015919.113.png 1256015919.114.png 1256015919.115.png 1256015919.116.png 1256015919.117.png 1256015919.118.png 1256015919.119.png 1256015919.120.png 1256015919.122.png 1256015919.123.png 1256015919.124.png 1256015919.125.png 1256015919.126.png 1256015919.127.png 1256015919.128.png 1256015919.129.png 1256015919.130.png 1256015919.131.png 1256015919.133.png 1256015919.134.png 1256015919.135.png 1256015919.136.png 1256015919.137.png 1256015919.138.png 1256015919.139.png 1256015919.140.png 1256015919.141.png 1256015919.142.png 1256015919.144.png 1256015919.145.png 1256015919.146.png 1256015919.147.png 1256015919.148.png 1256015919.149.png
 
C6545_02 6/6/2007 8:55:2 Page 32
32
CHAPTER 2
The importance of data modeling cannot be overstated. Data constitute the most basic information units employed by
a system. Applications are created to manage data and to help transform data into information. But data are viewed
in different ways by different people. For example, contrast the (data) view of a company manager with that of a
company clerk. Although the manager and the clerk both work for the same company, the manager is more likely to
have an enterprise-wide view of company data than the clerk.
Even different managers view data differently. For example, a company president is likely to take a universal view of
the data because he or she must be able to tie the company’s divisions to a common (database) vision. A purchasing
manager in the same company is likely to have a more restricted view of the data, as is the company’s inventory
manager. In effect, each department manager works with a subset of the company’s data. The inventory manager is
more concerned about inventory levels, while the purchasing manager is more concerned about the cost of items and
about personal/business relationships with the suppliers of those items.
Applications programmers have yet another view of data, being more concerned with data location, formatting, and
specific reporting requirements. Basically, applications programmers translate company policies and procedures from
a variety of sources into appropriate interfaces, reports, and query screens.
The different users and producers of data and information often reflect the “blind people and the elephant” analogy:
the blind person who felt the elephant’s trunk had quite a different view of the elephant from the one who felt the
elephant’s leg or tail. What is needed is a view of the whole elephant. Similarly, a house is not a random collection
of rooms; if someone is going to build a house, he or she should first have the overall view that is provided by
blueprints. Likewise, a sound data environment requires an overall database blueprint based on an appropriate
data model.
When a good database blueprint is available, it does not matter that an applications programmer’s view of the data is
different from that of the manager and/or the end user. Conversely, when a good database blueprint is not available,
problems are likely to ensue. For instance, an inventory management program or an order entry system may use
conflicting product numbering schemes, thereby costing the company thousands (or even millions) of dollars.
Keep in mind that a house blueprint is an abstraction; you cannot live in the blueprint. Similarly, the data model is an
abstraction; you cannot draw the required data out of the data model. Just as you are not likely to build a good house
without a blueprint, you are equally unlikely to create a good database without first creating an appropriate data model.
2.3 DATA MODEL BASIC BUILDING BLOCKS
The basic building blocks of all data models are entities, attributes, relationships, and constraints. An entity is anything
(a person, a place, a thing, or an event) about which data are to be collected and stored. An entity represents a
particular type of object in the real world. Because an entity represents a particular type of object, entities are
“distinguishable” that is, each entity occurrence is unique and distinct. For example, a CUSTOMER entity would have
many distinguishable customer occurrences, such as John Smith, Pedro Dinamita, Tom Strickland, etc. Entities may
be physical objects, such as customers or products, but entities may also be abstractions, such as flight routes or musical
concerts.
An attribute is a characteristic of an entity. For example, a CUSTOMER entity would be described by attributes such
as customer last name, customer first name, customer phone, customer address, and customer credit limit. Attributes
are the equivalent of fields in file systems.
A relationship describes an association among entities. For example, a relationship exists between customers and
agents that can be described as follows: an agent can serve many customers, and each customer may be served by one
agent. Data models use three types of relationships: one-to-many, many-to-many, and one-to-one. Database designers
usually use the shorthand notations 1:M or 1..*, M:N or *..*, and 1:1 or 1..1, respectively. (Although the M:N notation
1256015919.150.png 1256015919.151.png 1256015919.152.png 1256015919.154.png 1256015919.155.png 1256015919.156.png 1256015919.157.png 1256015919.158.png 1256015919.159.png 1256015919.160.png 1256015919.161.png 1256015919.162.png 1256015919.163.png 1256015919.165.png 1256015919.166.png 1256015919.167.png 1256015919.168.png 1256015919.169.png 1256015919.170.png 1256015919.171.png 1256015919.172.png 1256015919.173.png 1256015919.174.png 1256015919.176.png 1256015919.177.png 1256015919.178.png 1256015919.179.png 1256015919.180.png 1256015919.181.png 1256015919.182.png 1256015919.183.png 1256015919.184.png 1256015919.185.png 1256015919.187.png 1256015919.188.png 1256015919.189.png 1256015919.190.png 1256015919.191.png 1256015919.192.png 1256015919.193.png 1256015919.194.png 1256015919.195.png 1256015919.196.png 1256015919.198.png 1256015919.199.png 1256015919.200.png 1256015919.201.png 1256015919.202.png 1256015919.203.png 1256015919.204.png 1256015919.205.png 1256015919.206.png 1256015919.207.png 1256015919.209.png 1256015919.210.png 1256015919.211.png 1256015919.212.png 1256015919.213.png 1256015919.214.png 1256015919.215.png 1256015919.216.png 1256015919.217.png 1256015919.218.png 1256015919.220.png 1256015919.221.png 1256015919.222.png 1256015919.223.png 1256015919.224.png 1256015919.225.png 1256015919.226.png 1256015919.227.png 1256015919.228.png 1256015919.229.png 1256015919.231.png 1256015919.232.png 1256015919.233.png 1256015919.234.png 1256015919.235.png 1256015919.236.png 1256015919.237.png 1256015919.238.png 1256015919.239.png 1256015919.240.png 1256015919.242.png 1256015919.243.png 1256015919.244.png 1256015919.245.png 1256015919.246.png 1256015919.247.png 1256015919.248.png 1256015919.249.png 1256015919.250.png 1256015919.251.png 1256015919.253.png 1256015919.254.png 1256015919.255.png 1256015919.256.png 1256015919.257.png 1256015919.258.png 1256015919.259.png 1256015919.260.png 1256015919.261.png 1256015919.262.png 1256015919.264.png 1256015919.265.png 1256015919.266.png 1256015919.267.png 1256015919.268.png 1256015919.269.png 1256015919.270.png 1256015919.271.png 1256015919.272.png 1256015919.273.png 1256015919.275.png 1256015919.276.png 1256015919.277.png 1256015919.278.png 1256015919.279.png 1256015919.280.png 1256015919.281.png 1256015919.282.png 1256015919.283.png 1256015919.284.png 1256015919.286.png 1256015919.287.png 1256015919.288.png 1256015919.289.png 1256015919.290.png 1256015919.291.png 1256015919.292.png 1256015919.293.png 1256015919.294.png 1256015919.295.png 1256015919.297.png 1256015919.298.png 1256015919.299.png 1256015919.300.png 1256015919.301.png 1256015919.302.png 1256015919.303.png 1256015919.304.png 1256015919.305.png 1256015919.306.png 1256015919.308.png 1256015919.309.png 1256015919.310.png 1256015919.311.png 1256015919.312.png
C6545_02 6/4/2007 15:32:25 Page 33
33
DATA MODELS
is a standard label for the many-to-many relationship, the label M:M may also be used.) The following examples
illustrate the distinctions among the three.
One-to-many (1:M or 1..*) relationship . A painter paints many different paintings, but each one of them
is painted by only one painter. Thus, the painter (the “one”) is related to the paintings (the “many”). Therefore,
database designers label the relationship “PAINTER paints PAINTING” as 1:M. (Note that entity names are
often capitalized as a convention so they are easily identified.) Similarly, a customer (the “one”) may generate
many invoices, but each invoice (the “many”) is generated by only a single customer. The “CUSTOMER
generates INVOICE” relationship would also be labeled 1:M.
Many-to-many (M:N or *..*) relationship . An employee may learn many job skills, and each job skill may
be learned by many employees. Database designers label the relationship “EMPLOYEE learns SKILL” as M:N.
Similarly, a student can take many classes and each class can be taken by many students, thus yielding the M:N
relationship label for the relationship expressed by “STUDENT takes CLASS.”
One-to-one (1:1 or 1..1) relationship . A retail company’s management structure may require that each of
its stores be managed by a single employee. In turn, each store manager, who is an employee, manages only
a single store. Therefore, the relationship “EMPLOYEE manages STORE” is labeled 1:1.
The preceding discussion identified each relationship in both directions; that is, relationships are bidirectional:
One CUSTOMER can generate many INVOICEs.
Each of the many INVOICEs is generated by only one CUSTOMER.
A constraint is a restriction placed on the data. Constraints are important because they help to ensure data integrity.
Constraints are normally expressed in the form of rules. For example:
An employee’s salary must have values that are between 6,000 and 350,000.
A student’s GPA must be between 0.00 and 4.00.
Each class must have one and only one teacher.
How do you properly identify entities, attributes, relationships, and constraints? The first step is to clearly identify the
business rules for the problem domain you are modeling.
2.4 BUSINESS RULES
When database designers go about selecting or determining the entities, attributes, and relationships that will be used
to build a data model, they might start by gaining a thorough understanding of what types of data are in an
organization, how the data are used, and in what time frames they are used. But such data and information do not,
by themselves, yield the required understanding of the total business. From a database point of view, the collection of
data becomes meaningful only when it reflects properly defined business rules .A business rule is a brief, precise,
and unambiguous description of a policy, procedure, or principle within a specific organization. In a sense, business
rules are misnamed: they apply to any organization, large or small—a business, a government unit, a religious group,
or a research laboratory—that stores and uses data to generate information.
Business rules, derived from a detailed description of an organization’s operations, help to create and enforce actions
within that organization’s environment. Business rules must be rendered in writing and updated to reflect any change
in the organization’s operational environment.
Properly written business rules are used to define entities, attributes, relationships, and constraints. Any time you see
relationship statements such as “an agent can serve many customers, and each customer can be served by only one
agent , ” you are seeing business rules at work. You will see the application of business rules throughout this book,
especially in the chapters devoted to data modeling and database design.
1256015919.313.png 1256015919.314.png 1256015919.315.png 1256015919.316.png 1256015919.317.png 1256015919.319.png 1256015919.320.png 1256015919.321.png 1256015919.322.png 1256015919.323.png 1256015919.324.png 1256015919.325.png 1256015919.326.png 1256015919.327.png 1256015919.328.png 1256015919.330.png 1256015919.331.png 1256015919.332.png 1256015919.333.png 1256015919.334.png 1256015919.335.png 1256015919.336.png 1256015919.337.png 1256015919.338.png 1256015919.339.png 1256015919.341.png 1256015919.342.png 1256015919.343.png 1256015919.344.png 1256015919.345.png 1256015919.346.png 1256015919.347.png 1256015919.348.png 1256015919.349.png 1256015919.350.png 1256015919.352.png 1256015919.353.png 1256015919.354.png 1256015919.355.png 1256015919.356.png 1256015919.357.png 1256015919.358.png 1256015919.359.png 1256015919.360.png 1256015919.361.png 1256015919.363.png 1256015919.364.png 1256015919.365.png 1256015919.366.png 1256015919.367.png 1256015919.368.png 1256015919.369.png 1256015919.370.png 1256015919.371.png 1256015919.372.png 1256015919.374.png 1256015919.375.png 1256015919.376.png 1256015919.377.png 1256015919.378.png 1256015919.379.png 1256015919.380.png 1256015919.381.png 1256015919.382.png 1256015919.383.png 1256015919.385.png 1256015919.386.png 1256015919.387.png 1256015919.388.png 1256015919.389.png 1256015919.390.png 1256015919.391.png 1256015919.392.png 1256015919.393.png 1256015919.394.png 1256015919.396.png 1256015919.397.png 1256015919.398.png 1256015919.399.png 1256015919.400.png 1256015919.401.png 1256015919.402.png 1256015919.403.png 1256015919.404.png 1256015919.405.png 1256015919.407.png 1256015919.408.png 1256015919.409.png 1256015919.410.png 1256015919.411.png 1256015919.412.png 1256015919.413.png 1256015919.414.png 1256015919.415.png 1256015919.416.png 1256015919.418.png 1256015919.419.png 1256015919.420.png 1256015919.421.png 1256015919.422.png 1256015919.423.png 1256015919.424.png 1256015919.425.png 1256015919.426.png 1256015919.427.png 1256015919.429.png 1256015919.430.png 1256015919.431.png 1256015919.432.png 1256015919.433.png 1256015919.434.png 1256015919.435.png 1256015919.436.png 1256015919.437.png 1256015919.438.png 1256015919.440.png 1256015919.441.png 1256015919.442.png 1256015919.443.png 1256015919.444.png 1256015919.445.png 1256015919.446.png 1256015919.447.png 1256015919.448.png 1256015919.449.png 1256015919.451.png 1256015919.452.png 1256015919.453.png 1256015919.454.png 1256015919.455.png 1256015919.456.png 1256015919.457.png 1256015919.458.png 1256015919.459.png 1256015919.460.png 1256015919.462.png 1256015919.463.png 1256015919.464.png 1256015919.465.png 1256015919.466.png 1256015919.467.png 1256015919.468.png 1256015919.469.png 1256015919.470.png 1256015919.471.png 1256015919.473.png 1256015919.474.png 1256015919.475.png
C6545_02 6/4/2007 14:5:26 Page 34
34
CHAPTER 2
To be effective, business rules must be easy to understand and widely disseminated to ensure that every person in the
organization shares a common interpretation of the rules. Business rules describe, in simple language, the main and
distinguishing characteristics of the data as viewed by the company . Examples of business rules are as follows:
A customer may generate many invoices.
An invoice is generated by only one customer.
A training session cannot be scheduled for fewer than 10 employees or for more than 30 employees.
Note that those business rules establish entities, relationships, and constraints. For example, the first two business rules
establish two entities (CUSTOMER and INVOICE) and a 1:M relationship between those two entities. The third
business rule establishes a constraint (no fewer than 10 people and no more than 30 people), two entities (EMPLOYEE
and TRAINING), and a relationship between EMPLOYEE and TRAINING.
2.4.1 DISCOVERING BUSINESS RULES
The main sources of business rules are company managers, policy makers, department managers, and written
documentation such as a company’s procedures, standards, or operations manuals. A faster and more direct source
of business rules is direct interviews with end users. Unfortunately, because perceptions differ, end users sometimes are
a less reliable source when it comes to specifying business rules. For example, a maintenance department mechanic
might believe that any mechanic can initiate a maintenance procedure, when actually only mechanics with inspection
authorization can perform such a task. Such a distinction might seem trivial, but it can have major legal consequences.
Although end users are crucial contributors to the development of business rules, it pays to verify end-user
perceptions . Too often, interviews with several people who perform the same job yield very different perceptions of
what the job components are. While such a discovery may point to “management problems,” that general diagnosis
does not help the database designer. The database designer’s job is to reconcile such differences and verify the results
of the reconciliation to ensure that the business rules are appropriate and accurate.
The process of identifying and documenting business rules is essential to database design for several reasons:
They help standardize the company’s view of data.
They can be a communications tool between users and designers.
They allow the designer to understand the nature, role, and scope of the data.
They allow the designer to understand business processes.
They allow the designer to develop appropriate relationship participation rules and constraints and to create
an accurate data model.
Of course, not all business rules can be modeled. For example, a business rule that specifies that “no pilot can fly more
than 10 hours within any 24-hour period” cannot be modeled. However, such a business rule can be enforced by
application software.
2.4.2 TRANSLATING BUSINESS RULES INTO DATA MODEL COMPONENTS
Business rules set the stage for the proper identification of entities, attributes, relationships, and constraints. In the real
world, names are used to identify objects. If the business environment wants to keep track of the objects, there will be
specific business rules for them. As a general rule, a noun in a business rule will translate into an entity in the model,
and a verb (active or passive) associating nouns will translate into a relationship among the entities. For example, the
business rule “a customer may generate many invoices” contains two nouns ( customer and invoices ) and a verb
( generate ) that associates the nouns. From this business rule, you could deduct that:
Customer and invoice are objects of interest for the environment and should be represented by their respective
entities.
There is a “generate” relationship between customer and invoice.
1256015919.476.png 1256015919.477.png 1256015919.478.png 1256015919.479.png
 
Zgłoś jeśli naruszono regulamin