NORMALIZING AND DENORMALIZING DATA pot

36 136 0
  • Loading ...
    Loading ...
    Loading ...

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Tài liệu liên quan

Thông tin tài liệu

Ngày đăng: 01/08/2014, 09:22

2B.1 Relational Database Desi g n L L E E S S S S O O N N : : 2 2 B B N N O O R R M M A A L L I I Z Z I I N N G G A A N N D D D D E E N N O O R R M M A A L L I I Z Z I I N N G G D D A A T T A A O O b b j j e e c c t t i i v v e e s s In this section, you will learn to:  Describe the Top-down and Bottom-up approach  Describe data redundancy  Describe the first, second, and third normal forms  Describe the Boyce-Codd Normal Form (BCNF)  Appreciate the need for denormalization 2B.2 Relational Database Desi g n 2B.3 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18©NIIT Normalizing and Denormalizing Data Objectives In this section, you will learn to: • Describe the Top-down and Bottom-up approach • Describe data redundancy • Describe the first, second, and third normal forms • Describe the Boyce-Codd Normal Form (BCNF) • Appreciate the need for denormalization I I N N S S T T R R U U C C T T O O R R N N O O T T E E S S Lesson Overview The lesson introduces the top-down and bottom-up approaches of logical database design. This lesson also explains normalization as a technique to avoid data redundancy and covers the various normal forms. In addition, this lesson explains denormalization as a technique for improving query performance. 2B.4 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 2 of 18©NIIT Normalizing and Denormalizing Data Pre-assessment Questions 1. The scenario where a student can do only one project and no other student can do the same project, the relationship between student and project is a ______ relationship. a. One-to-One b. One-to-Many c. Many-to-One d. Many-to-Many 2. Which of the following options is true? a. The primary key of the supertype is the primary key of the subtype. b. The foreign key of the supertype is the primary key of the subtype. c. The primary key of the supertype is the foreign key of the subtype. d. The foreign key of the supertype is the foreign key of the subtype. 2B.5 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 3 of 18©NIIT Normalizing and Denormalizing Data Pre-assessment Questions (Contd ) 3. A candidate key that does not become a primary key is called a(n) ______ key. a. Candidate key b. Foreign key c. Alternate key d. Composite key 4. Which of the following problems arise when a primary key is allowed NULL values? a. It becomes difficult to identify the rows uniquely. b. It becomes difficult to identify the columns uniquely. c. It becomes difficult to join tables. d. It becomes difficult to identify foreign key. 5. In ______, every higher-level entity must also be a lower-level entity. a. Generalization b. E/R diagram c. Specialization d. Many-to-Many relationship 2B.6 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 4 of 18©NIIT Normalizing and Denormalizing Data Solutions Ans1. One-to-One Ans2 . The primary key of the supertype is the foreign key of the subtype. Ans3. Alternate key Ans4. It becomes difficult to identify the rows uniquely. Ans5. Generalization 2B.7 Relational Database Desi g n N N O O R R M M A A L L I I Z Z A A T T I I O O N N Top-Down and Bottom-Up Approach Normalizing and Denormalizing Data Lesson 2B / Slide 5 of 18©NIIT Normalizing and Denormalizing Data Top-Down and Bottom-Up Approach • There are two approaches to logical database design: • The top-down approach • The bottom-up approach • The E/R modeling technique is the top-down approach. It involves identifying entities, relationships and attributes, drawing the E/R diagram, and mapping the diagram to tables. • Normalization is the bottom-up approach. It is a step-by-step decomposition of complex records into simple records. • Normalization reduces redundancy using the principle of non-loss decomposition. • Non-loss decomposition is the reduction of a table to smaller tables without any loss of information. • The bottom-up approach is best for validation of existing designs. In the previous sessions, we described logical database design using the entity- relationship diagramming technique. There are two approaches to logical database design: The top-down approach The bottom-up approach 2B.8 Relational Database Desi g n The E/R modeling technique is the top-down approach. It involves identifying entities, relationships and attributes, drawing the E/R diagram, and mapping the diagram to tables. In this session, we will explain Normalization, which is the bottom-up approach. Normalization is a step-by-step decomposition of complex records into simple records. Normalization reduces redundancy using the principle of non-loss decomposition. Non- loss decomposition is the reduction of a table to smaller tables without any loss of information. Very often, the process of normalization follows the process of drawing E/R diagrams. However, depending on how detailed and precise the E/R diagram is, the process of normalization may not be necessary at all. The tables derived from the E/R diagram may already be normalized. In fact, they will always be at least in the first normal form. Persons strictly following the bottom-up approach do not go through the E/R modeling process at all. After the collection of data to be stored in the database is complete, the data is normalized. The top-down approach is best for validation of existing designs. Data Redundancy Normalizing and Denormalizing Data Lesson 2B / Slide 6 of 18©NIIT Normalizing and Denormalizing Data Data Redundancy • Redundancy means repetition of data. • Redundancy increases the time involved in updating, adding, and deleting data. • Redundancy also increases the utilization of disk space, and hence, disk I/O increases. • Redundancy can lead to: • Update anomalies—Inserting, modifying, and deleting data may cause inconsistencies. • Inconsistencies—Errors are more likely to occur when facts are repeated. • Unnecessary utilization of extra disk space. 2B.9 Relational Database Desi g n Redundancy means repetition of data. Redundancy increases the time involved in updating, adding, and deleting data. It also increases the utilization of disk space and hence, disk I/O increases. For example, consider the structure of the Student table: Student StudentId StudentName StudentBirthdate StudentAddress StudentCity StudentZip StudentClass StudentSemester StudentTest1 StudentTest2 The sample data for the Student table would be: Student ID Student Name …… StudentSemester Student Test1 Student Test2 001 Mary …… SEM-1 40 65 001 Mary …… SEM-2 56 48 002 Jake …… SEM-1 93 84 002 Jake …… SEM-2 85 90 The details of the students along with the marks are present in one table called Student. The details of the students like StudentId, StudentName, and StudentAddress are repeated while recording marks of different semesters. The repeated data is redundant. In addition, if you need to modify the address of a student, it has to be modified in multiple rows for that student. If not done, it could lead to data inconsistency across rows. 2B.10 Relational Database Desi g n If there are one thousand students and the details for each student occupies two hundred bytes, then two hundred thousand bytes are repeated. Hence, a lot of disk space is used up unnecessarily. Redundancy can, therefore, lead to: Update anomalies—Inserting, modifying, and deleting data may cause inconsistencies. Inconsistencies—Errors are more likely to occur when facts are repeated.  Unnecessary utilization of extra disk space. You can use your experience and common sense to design a database. However, you can use systematic approaches like normalization to reduce redundancy and duplicity. Need for Normalization Normalizing and Denormalizing Data Lesson 2B / Slide 7 of 18©NIIT Normalizing and Denormalizing Data Need for Normalization • Normalization is a scientific method of breaking down complex table structures into simple table structures by using certain rules. • Using normalization, you can reduce redundancy in a table and eliminate the problems of inconsistency and disk space usage. • You can also ensure that there is no loss of information. • Normalization has several benefits as follows: • It enables faster sorting and index creation. • It helps to create more clustered indexes. • It requires few indexes per table. • It reduces the number of NULL values in a table. • It makes the database compact. [...]... 2NF when it is in 1 NF and every attribute in the row is functionally dependent upon the whole key, and not just part of the key A table is said to be in the 3NF when it is in 2 NF and every non-key attribute is functionally dependent only on the primary key Normalizing and Denormalizing Data Lesson 2B / Slide 17 of 18 Relational Database Design Normalizing and Denormalizing Data Summary (Contd ) •... formation of tables that satisfy certain specified constraints, and represent certain normal forms • A table structure is always in a certain normal form ©NIIT Normalizing and Denormalizing Data Relational Database Design Lesson 2B / Slide 16 of 18 2B.32 Normalizing and Denormalizing Data Summary (Contd ) • • • • • ©NIIT 2B.33 The most important and widely used normal forms are: • First Normal Form (1 NF)... about data redundancy: Data redundancy results in wastage of space and loss of data integrity in the database Data redundancy leads to three types of anomalies These are: 1 Update anomaly: This is data inconsistency resulting from data redundancy and partial update 2 Deletion anomaly: This is the unintended loss of data due to deletion of other data 3 Insertion anomaly: This is the inability to add data. .. dependencies 2B.17 Relational Database Design First Normal Form (1 NF) Normalizing and Denormalizing Data First Normal Form (1 NF) • ©NIIT A table is said to be in the 1 NF when each cell of the table contains precisely one value Normalizing and Denormalizing Data Lesson 2B / Slide 11 of 18 A table is said to be in the 1 NF when each cell of the table contains precisely one value Relational Database Design 2B.18... data to the database due to absence of other data Relational Database Design 2B.12 DIFFERENT NORMAL FORMS AND DENORMALIZATION Normal Forms Normalizing and Denormalizing Data Normal Forms • • • • ©NIIT Normalization results in the formation of tables that satisfy certain specified rules and represent certain normal forms The normal forms are used to ensure that various types of anomalies and inconsistencies... above conditions A relation is in BCNF if and only if every determinant is a candidate key Guidelines for converting a table to BCNF: • Find and remove the overlapping candidate keys Place the part of the candidate key and the attribute it is functionally dependent on, in a different table • Group the remaining items into a table Normalizing and Denormalizing Data Lesson 2B / Slide 14 of 18 The original... Finance E608 2B.25 Systems Finance Relational Database Design Boyce-Codd Normal Form Normalizing and Denormalizing Data Boyce-Codd Normal Form (BCNF) • • • • ©NIIT The original definition of 3 NF was inadequate and not satisfactory for the tables: • that had multiple candidate keys • where the multiple candidate keys were composite • where the multiple candidate keys overlapped The Boyce-Codd Normal... Relational Database Design Second Normal Form (2 NF) Normalizing and Denormalizing Data Second Normal Form (2 NF) • • ©NIIT A table is said to be in 2 NF when it is in 1 NF and every attribute in the row is functionally dependent upon the whole key, and not just part of the key Guidelines for converting a table to 2 NF: • Find and remove attributes that are functionally dependent on only a part of the key and. .. ProjCode, and Hours EmployeeDept ECode Dept Project DeptHead Ecode ProjCode Hours E101 Systems E901 E101 P27 90 E305 Finance E909 E101 P51 101 E508 Admin E908 E101 P20 60 E305 P27 10 E508 P51 NULL E508 P27 72 Relational Database Design 2B.22 Third Normal Form (3 NF) Normalizing and Denormalizing Data Third Normal Form (3 NF) • • ©NIIT A table is said to be in the 3 NF when it is in 2 NF and every nonkey... The first, second, and third normal forms were originally defined by Dr E F Codd Later, Boyce and Codd introduced another normal form called the Boyce-Codd Normal Form As displayed in the above figure, a relation that is in first normal form may also be in second normal form or third normal form Relational Database Design 2B.14 Functional Dependency Normalizing and Denormalizing Data Functional Dependency . denormalization 2B.2 Relational Database Desi g n 2B.3 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18©NIIT Normalizing and Denormalizing Data Objectives In this. subtype. 2B.5 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 3 of 18©NIIT Normalizing and Denormalizing Data Pre-assessment Questions (Contd ) 3. A candidate key that. improving query performance. 2B.4 Relational Database Desi g n Normalizing and Denormalizing Data Lesson 2B / Slide 2 of 18©NIIT Normalizing and Denormalizing Data Pre-assessment Questions 1. The scenario
- Xem thêm -

Xem thêm: NORMALIZING AND DENORMALIZING DATA pot, NORMALIZING AND DENORMALIZING DATA pot, NORMALIZING AND DENORMALIZING DATA pot