1

Chương 3

Mô hình hóa dữ liệu

Quy tắc nghiệp vụ và mô hình hóa dữ liệu

2

Quy tắc nghiệp vụ Business rules

 Quy tắc nghiệp vụ thường không có cấu trúc rõ

ràng  Nên loại bỏ các chi tiết thừa

 Bổ sung các chi tiết bị thiếu

 Tạo ra lược đồ ER phù hợp với mô tả bài toán  Nên chọn thiết kế đơn giản hơn trong giai đoạn

đầu

 Nên làm rõ những phát biểu không rõ ràng hoặc

thiếu chi tiết.

Mục đích của phân tích bài toán Goals of Narrative Problem Analysis

 Nhận diện các kiểu thực thể và thuộc tính  Xác định khóa chính  Xác định mối quan hệ  Xác định lượng số  Làm đơn gián mối quan hệ phức

Các bước phân tích bài toán

5

Case study:

The water utility database should support the recording of water usage and billing for water usage. To support these functions, the database should contain data about customers, rates, water usage, and bills.

6

y d u

 Customer data include a unique customer number, a name, a billing address, a type (commercial or residential), an applicable rate, and a collection (one or more) of meters.  Meter data include a unique meter number, an address, a size, and a model. The meter number is engraved on the meter before it is placed in service. A meter is associated with one customer at a time.

t s e s a C

7

 An employee periodically reads each meter on a scheduled date. When a meter is read, a meter-reading document is created containing a unique meter reading number, an employee number, a meter number, a timestamp, and a consumption level.

y d u

t s e s a C

 A rate includes a unique rate number, a description, a fixed dollar amount, a consumption threshold, and a variable amount. Consumption up to the threshold is billed at the fixed amount. Consumption greater than the threshold is billed at the variable amount. Customers are assigned rates using a factors such as customer type, address, and number of adjustment factors. Many customers can be assigned the same rate. Rates are typically proposed months before approved and associated with customers.

8

y d u

t s e s a C

 The water utility bills are based on customers' most recent meter readings and applicable rates. A bill consists of a heading part and a list of detail lines. The heading part contains a unique bill number, a customer number, a preparation date, a payment due date, and a date range for the consumption period. Each detail line contains a meter number, a water consumption level, and an amount. The water consumption level is computed by subtracting the consumption levels in the two most recent meter readings. The amount is computed by multiplying the consumption level by the customer's rate.

 Đối với kiểu thực thể, tìm danh từ biểu diễn

nhóm người, nơi chốn, sự kiện, ..

 Đối với thuộc tính, tìm các tính chất mô tả chi tiết

về kiểu thực thể.

 Nguyên tắc đơn giản hóa: nêú bài toán không mô tả thêm chi tiết một danh từ thì nên xem danh từ đó như thuộc tính

Xác định các kiểu thực thể và thuộc tính

 Stable: không thay đổi sau khi gán giá trị  Single purpose: không dùng thêm cho mục

Nguyên tắc xác định khóa chính

 Good choices: nên tự động tạo giá trị cho

đích khác

 Có thể khóa chính buộc phải xác định theo

khóa chính

yêu câu của tổ chức dù không tối ưu.

Xác định thực thể và thuộc tính

Xác định mối quan hệ

 Nhận diện mối quan hệ kết nối giữa các kiểu thực

thể dựa vào các quy tắc nghiệp vụ

Xác định mối quan hệ

Tinh chỉnh lược đồ

 Xây dựng lược đồ ER đầu tiên  Chỉnh sửa nhiều lần  Đánh giá xem có phù hợp với yêu cầu của tổ

chức

 Thu thập thêm các yêu cầu phụ nếu cần  Biến đổi để lược đồ có tính khả thi hơn

Chuyển đổi thuộc tính thành kiểu thực thể

Mở rộng kiểu thực thể

Biến đổi thực thể yếu thành thực thể mạnh

Thêm history vào thuộc tính

Thêm history vào mối quan hệ

Khái quát hóa khi thực thể có sự phân cấp