Phụ Thuộc Chức Năng và Chuẩn Hóa Cơ Sở Dữ Liệu: Chương 7

Chuyên khảo phân tích 7 fd1, đánh giá các khía cạnh quan trọng, đề xuất hướng nghiên cứu tiếp theo., phục vụ nghiên cứu và ứng dụng thực tiễn

Trường đại học

Trường ĐH Bách Khoa TPHCM

Người đăng

Ẩn danh

Thể loại

bài luận

2008

79
4
0

Phí lưu trữ

30 Point

Mục lục chi tiết

7. Chapter 7: Contents

7.1. Introduction

7.2. Functional dependencies

7.3. Normalization

1. Introduction

1.1. Overview of Database Miniworld Design Process

1.2. Requirements - Collection & Analysis

1.2.1. Functional requirements

1.2.2. Data requirements

1.2.3. DBMS–independent

1.3. Functional Analysis

1.4. Conceptual Design

1.4.1. High-level transaction

1.4.2. Conceptual schema specification

1.5. Logical Design (Data Model Mapping)

1.6. DBMS–specific Application Program

1.7. Database schema Design

1.8. Physical Design

1.9. Transaction Internal schema Implementation Application program

1.10. Introduction

1.10.1. Goodness measures

1.10.2. Redundant information in tuples

1.10.3. Update anomalies: modification, deletion, insertion

1.10.4. Reducing the NULL values in tuples

1.10.5. Disallowing the possibility of generating spurious tuples

1.11. Normalization

1.11.1. Normalization helps DB designers determine the best relation schemas

1.11.2. Properties of decompositions

2. Functional Dependencies (FDs)

2.1. Definition of FDs

2.2. Direct, indirect, partial dependencies

2.3. Inference Rules for FDs

2.4. Equivalence of Sets of FDs

2.5. Minimal Sets of FDs

2.6. Examples and Exercises

3. Normalization

3.1. Normalization process and normal forms

3.2. Prime and Nonprime attributes

3.3. 1NF and dependency problems

3.4. 2NF – solves partial dependency

3.5. 3NF – solves indirect dependency

3.6. BCNF – well-normalized relations

Tóm tắt

I. Hướng Dẫn Tổng Quan Về Phụ Thuộc Chức Năng Trong Cơ Sở Dữ Liệu

Phụ thuộc chức năng là một khái niệm quan trọng trong thiết kế cơ sở dữ liệu. Nó giúp xác định mối quan hệ giữa các thuộc tính trong một bảng. Việc hiểu rõ về phụ thuộc chức năng sẽ giúp các nhà thiết kế cơ sở dữ liệu tạo ra các mô hình dữ liệu hiệu quả hơn. Bài viết này sẽ cung cấp cái nhìn tổng quan về phụ thuộc chức năng và tầm quan trọng của nó trong việc chuẩn hóa cơ sở dữ liệu.

1.1. Định Nghĩa Phụ Thuộc Chức Năng Là Gì

Phụ thuộc chức năng (FD) là một ràng buộc giữa hai tập hợp thuộc tính trong một bảng. Nếu một thuộc tính X xác định duy nhất một thuộc tính Y, thì ta nói rằng Y phụ thuộc vào X. Điều này có nghĩa là nếu hai bản ghi có cùng giá trị của X, chúng cũng phải có cùng giá trị của Y.

1.2. Các Loại Phụ Thuộc Chức Năng

Có nhiều loại phụ thuộc chức năng, bao gồm phụ thuộc trực tiếp, gián tiếp và một phần. Mỗi loại phụ thuộc này có vai trò quan trọng trong việc xác định cấu trúc của cơ sở dữ liệu và giúp giảm thiểu sự dư thừa thông tin.

II. Những Thách Thức Trong Việc Chuẩn Hóa Cơ Sở Dữ Liệu

Chuẩn hóa cơ sở dữ liệu là quá trình tổ chức lại dữ liệu để giảm thiểu sự dư thừa và cải thiện tính toàn vẹn. Tuy nhiên, quá trình này cũng gặp phải nhiều thách thức. Các vấn đề như thông tin dư thừa, các lỗi cập nhật và các giá trị NULL có thể gây khó khăn cho việc thiết kế cơ sở dữ liệu hiệu quả.

2.1. Vấn Đề Thông Tin Dư Thừa

Thông tin dư thừa xảy ra khi cùng một thông tin được lưu trữ nhiều lần trong cơ sở dữ liệu. Điều này không chỉ làm tăng kích thước cơ sở dữ liệu mà còn có thể dẫn đến các lỗi trong quá trình cập nhật dữ liệu.

2.2. Các Lỗi Cập Nhật Trong Cơ Sở Dữ Liệu

Các lỗi cập nhật xảy ra khi một thay đổi trong dữ liệu không được phản ánh đúng ở tất cả các nơi mà dữ liệu đó được lưu trữ. Điều này có thể dẫn đến sự không nhất quán trong cơ sở dữ liệu và làm giảm độ tin cậy của thông tin.

III. Phương Pháp Chuẩn Hóa Cơ Sở Dữ Liệu Hiệu Quả

Có nhiều phương pháp để chuẩn hóa cơ sở dữ liệu, bao gồm các dạng chuẩn như 1NF, 2NF, 3NF và BCNF. Mỗi dạng chuẩn có các quy tắc riêng để đảm bảo rằng dữ liệu được tổ chức một cách hợp lý và hiệu quả.

3.1. Dạng Chuẩn Thứ Nhất 1NF

Dạng chuẩn thứ nhất yêu cầu rằng mỗi ô trong bảng chỉ chứa một giá trị duy nhất. Điều này có nghĩa là không có thuộc tính nào có thể chứa nhiều giá trị. Việc đạt được 1NF là bước đầu tiên trong quá trình chuẩn hóa.

3.2. Dạng Chuẩn Thứ Hai 2NF

Dạng chuẩn thứ hai yêu cầu rằng tất cả các thuộc tính không khóa phải phụ thuộc hoàn toàn vào khóa chính. Điều này giúp loại bỏ các phụ thuộc một phần và giảm thiểu sự dư thừa thông tin.

3.3. Dạng Chuẩn Thứ Ba 3NF

Dạng chuẩn thứ ba yêu cầu rằng không có thuộc tính không khóa nào phụ thuộc vào thuộc tính không khóa khác. Điều này giúp loại bỏ các phụ thuộc gián tiếp và đảm bảo rằng dữ liệu được tổ chức một cách hợp lý.

IV. Ứng Dụng Thực Tiễn Của Chuẩn Hóa Cơ Sở Dữ Liệu

Chuẩn hóa cơ sở dữ liệu không chỉ là lý thuyết mà còn có nhiều ứng dụng thực tiễn. Việc áp dụng các nguyên tắc chuẩn hóa giúp cải thiện hiệu suất của cơ sở dữ liệu và giảm thiểu các vấn đề liên quan đến dữ liệu.

4.1. Cải Thiện Hiệu Suất Cơ Sở Dữ Liệu

Khi cơ sở dữ liệu được chuẩn hóa, việc truy vấn dữ liệu trở nên nhanh chóng và hiệu quả hơn. Điều này giúp giảm thời gian phản hồi và cải thiện trải nghiệm người dùng.

4.2. Giảm Thiểu Các Vấn Đề Liên Quan Đến Dữ Liệu

Chuẩn hóa giúp giảm thiểu các vấn đề như thông tin dư thừa và các lỗi cập nhật. Điều này không chỉ giúp duy trì tính toàn vẹn của dữ liệu mà còn giảm thiểu chi phí bảo trì cơ sở dữ liệu.

V. Kết Luận Về Phụ Thuộc Chức Năng và Chuẩn Hóa Cơ Sở Dữ Liệu

Phụ thuộc chức năng và chuẩn hóa cơ sở dữ liệu là hai khái niệm quan trọng trong thiết kế cơ sở dữ liệu. Việc hiểu rõ và áp dụng chúng sẽ giúp tạo ra các cơ sở dữ liệu hiệu quả và đáng tin cậy. Tương lai của thiết kế cơ sở dữ liệu sẽ tiếp tục phát triển với sự gia tăng của dữ liệu lớn và các công nghệ mới.

5.1. Tương Lai Của Thiết Kế Cơ Sở Dữ Liệu

Với sự phát triển của công nghệ, thiết kế cơ sở dữ liệu sẽ ngày càng trở nên phức tạp hơn. Các nhà thiết kế cần phải nắm vững các nguyên tắc chuẩn hóa để đảm bảo rằng cơ sở dữ liệu có thể mở rộng và duy trì hiệu suất cao.

5.2. Tầm Quan Trọng Của Việc Đào Tạo

Đào tạo và nâng cao nhận thức về phụ thuộc chức năng và chuẩn hóa cơ sở dữ liệu là rất quan trọng. Điều này sẽ giúp các nhà phát triển và quản trị viên cơ sở dữ liệu tạo ra các giải pháp hiệu quả hơn trong tương lai.

15/07/2025

Trích đoạn nội dung tài liệu

Functional Dependencies & Normalization for Relational DBs Chapter 7 Contents 1 Introduction 2 Functional dependencies 3 Normalization 2 Contents 1 Introduction 2 Functional dependencies 3 Normalization 3 Overview of Database Miniworld Design Process REQUIREMENTS - COLLECTION & ANALYSIS Functional requirements Data requirements DBMS–independent FUNCTIONAL ANALYSIS CONCEPTUAL DESIGN High-level transaction Conceptual schema specification LOGICAL DESIGN (DATA MODEL MAPPING) DBMS–specific APPLICATION PROGRAM Database schema DESIGN PHYSICAL DESIGN TRANSACTION Internal schema IMPLEMENTATION Application program 4 Application Design Database Design Introduction  Each relation schema consists of a number of attributes and the relational database schema consists of a number of relation schemas  Attributes are grouped to form a relation schema  Need some formal measure of why one grouping of attributes into a relation schema may be better than another 5 Introduction  “Goodness” measures:  Redundant information in tuples  Update anomalies: modification, deletion, insertion  Reducing the NULL values in tuples  Disallowing the possibility of generating spurious tuples 6 Introduction  Redundant information in tuples: the attribute values pertaining to a particular department (DNUMBER, DNAME, DMGRSSN) are repeated for every employee who works for that department. 7 Introduction  Update anomalies: modification, deletion, insertion  Modification  As the manager of a dept. changes we have to update many values according to employees working for that dept.  Easy to make the DB inconsistent 8 Introduction  Deletion: if Borg James E.

leaves, we delete his tuple and lose the existing of dept. 1, the name of dept. 1, and who is the manager of dept. 1 Introduction  Insertion:  How can we create a department before any employees are assigned to it ?? Introduction  Reducing the NULL values in tuples  Employees not assigned to any dept.: waste the storage space  Other difficulties: aggregation operations (e., COUNT, SUM) and joins 11 Introduction  Disallowing the possibility of generating spurious tuples EMP_PROJ (SSN, PNumber, Hours, EName, PName, PLocation) EMP_LOCS (EName, PLocation) EMP_PROJ1 (SSN, PNumber, Hours, PName, PLocation)  Generation of invalid and spurious data during JOINS: PLocation is the attribute that relates EMP_LOCS and EMP_PROJ1, and PLocation is neither a primary key nor a foreign key in either EMP_LOCS or EMP_PROJ1 12 Introduction  Disallowing the possibility of generating spurious tuples 13 Introduction  Disallowing the possibility of generating spurious tuples 14 Introduction  “Goodness” measures:  Redundant information in tuples  Update anomalies: modification, deletion, insertion  Reducing the NULL values in tuples  Disallowing the possibility of generating spurious tuples  Normalization 15 Introduction  Normalization helps DB designers determine the best relation schemas  A formal framework for analyzing relation schemas based on their keys and on the functional dependencies among their attributes  A series of normal form tests that can be carried out on individual relation schemas so that the relational database can be normalized to any desired degree  It is based on the concept of normal form 1NF, 2NF, 3NF, BCNF, 4NF, 5NF  It is a process which ensures that the data is structured in such a way that attributes are grouped with the PK.

Attributes that do not directly depend on PK may be extracted to form a new relation 16 Introduction  There are two important properties of decompositions: 1) non-additive or losslessness of the corresponding join 2) preservation of the functional dependencies  Note that property (1) is extremely important and cannot be sacrificed. Property (2) is less stringent and may be sacrificed 17 Contents 1 Introduction 2 Functional dependencies 3 Normalization 18 Functional Dependencies (FDs)  Definition of FDs  Direct, indirect, partial dependencies  Inference Rules for FDs  Equivalence of Sets of FDs  Minimal Sets of FDs 19 Functional Dependencies (FDs)  Functional dependencies (FDs) are used to specify formal measures of the "goodness" of relational designs  FDs and keys are used to define normal forms for relations  FDs are constraints that are derived from the meaning and interrelationships of the data attributes  A set of attributes X functionally determines a set of attributes Y if the value of X determines a unique value for Y XY 20 Functional Dependencies (FDs)  X  Y holds if whenever two tuples have the same value for X, they must have the same value for Y  For any two tuples t1 and t2 in any relation instance r(R): If t1[X]=t2[X], then t1[Y]=t2[Y]  X  Y in R specifies a constraint on all relation instances r(R)  Examples:  social security number determines employee name: SSN  EName  project number determines project name and location: PNumber  {PName, PLocation}  employee ssn and project number determines the hours per week that the employee works on the project: {SSN, PNumber}  Hours 21 Functional Dependencies (FDs)  If K is a key of R, then K functionally determines all attributes in R (since we never have two distinct tuples with t1[K]=t2[K]) 22 Functional Dependencies (FDs)  Definition of FDs  Direct, indirect, partial dependencies  Inference Rules for FDs  Equivalence of Sets of FDs  Minimal Sets of FDs 23 Functional Dependencies (FDs)  Direct dependency (fully functional dependency): All attributes in a R must be fully functionally dependent on the primary key (or the PK is a determinant of all attributes in R) SSN  {Name, BDate, Address, DNO} EMPLOYEE SSN Name BDate Address DNO 24 Functional Dependencies (FDs)  Indirect dependency (transitive dependency): Value of an attribute is not determined directly by the primary key DNO  DName EMP_DEPT SSN Name BDate Address DNO DName 25 Functional Dependencies (FDs)  Partial dependency  Composite determinant - more than one value is required to determine the value of another attribute, the combination of values is called a composite determinant {SSN, PNumber} in EMP_PROJ  Partial dependency - if the value of an attribute does not depend on an entire composite determinant, but only part of it, the relationship is known as the partial dependency SSN  EName , Pnumber  {PName, PLocation} EMP_PROJ SSN PNumber Hours EName PName PLocation 26 Functional Dependencies (FDs)  Definition of FD  Direct, indirect, partial dependencies  Inference Rules for FDs  Equivalence of Sets of FDs  Minimal Sets of FDs 27 Functional Dependencies (FDs)  Given a set of FDs F, we can infer additional FDs that hold whenever the FDs in F hold  Armstrong's inference rules:  IR1. (Reflexive) If Y ⊆ X, then X  Y  IR2. (Transitive) If X  Y and Y  Z, then X  Z Functional Dependencies (FDs)  Some additional inference rules that are useful:  Decomposition: If X -> YZ, then X -> Y and X -> Z  Union: If X -> Y and X -> Z, then X -> YZ  Psuedotransitivity: If X -> Y and WY -> Z, then WX -> Z  The last three inference rules, as well as any other inference rules, can be deduced from IR1, IR2, and IR3 (completeness property) Functional Dependencies (FDs)  Closure of a set F of FDs is the set F+ of all FDs that can be inferred from F  Closure of a set of attributes X with respect to F is the set X+ of all attributes that are functionally determined by X  X+ can be calculated by repeatedly applying IR1, IR2, IR3 using the FDs in F Exercise  Consider a relation R(A, B, C, D, E) with the following dependencies F: (1) AB  C, (2) CD  E, (3) DE  B  Find {A, B}+ , {A, B, D}+  Find F+ 31 Functional Dependencies (FDs)  Definition of FD  Direct, indirect, partial dependencies  Inference Rules for FDs  Equivalence of Sets of FDs  Minimal Sets of FDs 32 Functional Dependencies (FDs)  Two sets of FDs F and G are equivalent if F+ = G+  Definition:  F covers G if G+ ⊆ F+  F and G are equivalent if F covers G and G covers F  There is an algorithm for checking equivalence of sets of FDs 33 Functional Dependencies (FDs)  A set of FDs is minimal if it satisfies the following conditions:  Every dependency in F has a single attribute for its RHS.

 We cannot remove any dependency from F and have a set of dependencies that is equivalent to F.  We cannot replace any dependency X  A in F with a dependency Y  A, where Y proper-subset-of X ( Y subset-of X) and still have a set of dependencies that is equivalent to F Functional Dependencies (FDs)  Every set of FDs has an equivalent minimal set  There can be several equivalent minimal sets  There is no simple algorithm for computing a minimal set of FDs that is equivalent to a set F of FDs  To synthesize a set of relations, we assume that we start with a set of dependencies that is a minimal set Contents 1 Introduction 2 Functional dependencies 3 Normalization 36 Normalization  Normalization: The process of decomposing unsatisfactory "bad" relations by breaking up their attributes into smaller relations  Normal form: Using keys and FDs of a relation to certify whether a relation schema is in a particular normal form  Normalization is carried out in practice so that the resulting designs are of high quality and meet the desirable properties  The database designers need not normalize to the highest possible normal form (3NF, BCNF or 4NF) 37 Normalization  Two new concepts:  A Prime attribute must be a member of some candidate key  A Nonprime attribute is not a prime attribute: it is not a member of any candidate key 38 Normalization  1NF and dependency problems  2NF – solves partial dependency  3NF – solves indirect dependency  BCNF – well-normalized relations 39 Normalization  First normal form (1NF): there is only one value at the intersection of each row and column of a relation - no set valued attributes in 1NF  Disallows composite attributes, multivalued attributes, and nested relations  To be part of the formal definition of a relation in the basic (flat) relational model 40 1NF 41 1NF 42 1NF 43 1NF EMP_PROJ (SSN, PNumber, Hours, EName, PName, PLocation) 1. SSN, PNumber  Hours 2. PNumber  PName, PLocation 44 1NF EMP_PROJ (SSN, PNumber, Hours) EMP (SSN, EName) PROJ (PNumber, PName, PLocation) 1.

SSN, PNUMBER  HOURS 2. PNUMBER  PNAME, PLOCATION 45 Normalization  1NF and dependency problems  2NF – solves partial dependency  3NF – solves indirect dependency  BCNF – well-normalized relations 46 Normalization  Second normal form (2NF) - all attributes must be fully functionally dependent on the primary key  2NF solves partial dependency problem in 1NF  Method: identify primary keys and group attributes that relate to the key together to form separate new relations 47 2NF 48 2NF Problem with 2NF 49 Normalization  1NF and dependency problems  2NF – solves partial dependency  3NF – solves indirect dependency  BCNF – well-normalized relations 50

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ