1 / 28

Chapter 4 Functional Dependency and Normalization

Chapter 4 Functional Dependency and Normalization. 4.1. Functional Dependency. When we design a database for an enterprise, the main objective is to create an accurate representation of the data, relationships between the data and constraints on the data that is relevant to the enterprise

corine
Télécharger la présentation

Chapter 4 Functional Dependency and Normalization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 4Functional Dependency and Normalization

  2. 4.1. Functional Dependency • When we design a database for an enterprise, the main objective is to create an accurate representation of the data, relationships between the data and constraints on the data that is relevant to the enterprise • One or more database design techniques are used to achieve this objective • Normalization is one of these techniques • Before moving to the definition and application of normalization, it is important to have an understanding of "functional dependency " • The logical associations between data items that point the database designer in the direction of a good database design are referred to as determinant or dependent relationships

  3. Two data items A and B are said to be in a determinant or dependent relationship if certain values of data item B always appears with certain values of data item A • If the data item A is the determinant data item and B the dependent data item then the direction of the association is from A to B and not vice versa. • The essence of this idea is that if the existence of something, call it A, implies that B must exist and have a certain value, then we say that "B is functionallydependent on A" • We also often express this idea by saying that "A determinesB," or that "B is a function of A," or that "A functionally governs B"

  4. Often, the notions of functionality and functional dependency are expressed briefly by the statement, "If A, then B" • It is important to note that the value B must be unique for a given value of A, i.e., any given value of A must imply just one and only one value of B, in order for the relationship to qualify for the name "function " • However, this does not necessarily prevent different values of A from implying the same value of B • If B is functionally dependent on A it is denoted as A  B • A is called determinant and B is called dependent • Both A and B can refer to a single attribute or group of attributes

  5. A  B holds if whenever two tuples have the same value for A, they must have the same value for B • In general, a functional dependency is a relationship among attributes • In relational databases, we can have a determinant that governs one other attribute or several other attributes • Functional dependencies (FDs) are derived from the real-world constraints on the attributes • Partial Dependency • If we have composite primary key and if an attribute which is not a member of the primary key is dependent on some part of the primary key then that attribute is partially functionally dependent on the primary key

  6. Let {A,B} is the Primary Key and C is not key attribute, then if {A,B}CandBCorACthen C is partially functionally dependent on {A,B} • Full Dependency • If an attribute which is not a member of the primary key is not dependent on some part of the primary key but the whole key (if we have composite primary key) then that attribute is fully functionally dependent on the primary key • Let {A,B} is the Primary Key and C is not key attribute, then if {A,B}→C and B→C and A→C does not hold ( if B can not determine C and A can not determine C) then C is fully functionally dependent on {A,B}

  7. Transitive Dependency • In mathematics and logic, a transitive relationship is a relationship of the following form: "If A implies B, and if also B implies C, then A implies C " • Generalized way of describing transitive dependency is that: • If A functionally governs B, and B functionally governs C then A functionally governs C provided that neither C nor B determines A

  8. 4.2. Normal Forms • A relational database is merely a collection of data, organized in a particular manner • One of the best ways to determine what information should be stored in a database is to clarify what questions will be asked of it and what data would be included in the answers • Database normalization is a series of steps followed to obtain a database designthat allows for consistent storage and efficient access of data in a relational database • These steps reduce data redundancy and the risk of data becoming inconsistent • Normalization is the process of identifying the logical associationsbetween data items and designing a database that will represent such associations but without suffering the update anomalies

  9. Normalization may reduce system performance since data will be cross referenced from many tables • Thus denormalization is sometimes used to improve performance, at the cost of reduced consistency guarantees • Normalization normally is considered as good if it is lossless decomposition • All the normalization rules will eventually remove the update anomalies that may exist during data manipulation after the implementation • Normalization is a process of applying a series of rules to ensure that a database achieves an optimal structure • Normalization begins by examining the relationships between attributes called functional dependencies

  10. The purpose of normalization is to identify a suitable set of relations that support the data requirement of an enterprise • The characteristics of suitable relations include: • Minimal number of attributes to support the data requirement of an enterprise • Putting attributes with a close logical relationships in the same relation • Minimal redundancy with each attribute represented only once • Note:- the exception to the third characteristics is that of attributes that form all or part of foreign keys which are essential for the joining of related relations

  11. A major aim of relational database design is to group attributes into relations to minimize data redundancy • If data redundancy is minimized: • Updates to the data stored in the database are achieved with a minimal number of operations – reducing the opportunities for data inconsistencies occurring in the database • Reduction in the file storage required by the base relations thus minimizing costs • It is important to identify unwanted redundancies and required redundancies

  12. The type of problems that could occur in insufficiently normalized table is called update anomalies which includes: • Insertion anomalies • Deletion anomalies • Modification anomalies • Insertion anomalies • An "insertion anomaly" is a failure to place information about a new database entry into all the places in the database where information about that new entry needs to be stored • In a properly normalized database, information about a new entry needs to be inserted into only one place in the database; in an inadequately normalized database, information about a new entry may need to be inserted into more than one place

  13. Deletion anomalies • A "deletion anomaly" is a failure to remove information about an existing database entry when it is time to remove that entry • In a properly normalized database, information about an old, to-be-gotten-rid-of entry needs to be deleted from only one place in the database; in an inadequately normalized database, information about that old entry may need to be deleted from more than one place, and some of the needed deletions may be missed

  14. Modification anomalies • A modification of a database involves changing some value of the attribute of a table • In a properly normalized database table, what ever information is modified by the user, the change will be effected and used accordingly • The purpose of normalization is to reduce the chances for anomalies to occur in a database

  15. Example: consider the following tables that illustrate the problems with unwanted data redundancies • Staff(SNo,SName,Position,Salary,BNo) • Branch(BNo,BAddress) • StaffBranch(SNo,SName,Position,Salary,BNo,BAddress)

  16. StaffBranch

  17. In the StaffBranch relation there is redundant data • The details of a branch are repeated for every member of staff located at that branch • These type of relations that have redundant data may have problems called update anomalies (irregularities) • To enter details of a new member of staff into the StaffBaranch relation, we must include the details of the branch at which the staff are to be located • To enter details of a new branch that currently has no members of staff into the StaffBranch relation, it is necessary to enter NULL into attributes for staff such as SNo • However as SNo is the primary key for the StaffBranch relation, attempting to enter NULL into SNo violates entity integrity and is not allowed

  18. We therefore can not enter a tuple for a new branch into the StaffBranch relation with a NULL for the SNo • If we delete a tuple from the StaffBranch relation, the details about that branch are also lost from the database • E.g. if we delete the tuple for the staff number SA9(Aster) from the StaffBranch relation, the details relating to the branch number B007 are lost from the database • If we want to change the value of one of the attributes of a particular branch in the StaffBranch relation, e.g. the address for branch number B003, we must update the tuples of all staff located at that branch • If this modification is not carried out on all the appropriate tuples of the StaffBranch relation, the database will become inconsistent

  19. We avoid these update anomalies from the StaffBranch relation by decomposing the relation into two as Staff and Branch relations as follows:

  20. Staff Branch

  21. Branch details appear only once for each branch in the Branch relation • And only the BNo is repeated in the Staff relation to represent where each member of the staff is located • The latter two relations do not suffer from potential inconsistency because we enter only appropriate branch number for each staff member in the Staff relation • The details of the branch number B007 are recorded in the database as a single tuple in the Branch relation • Update anomalies will be avoided from the two relations Staff and Branch because branch details are stored into the Branch relation separately from staff details which is stored in the Staff relation

  22. There are two important properties associated with decomposition of a larger relation into smaller relations • The lossless-join property • Any instance of the original relation can be identified from the corresponding instances in the smaller relations • The dependency preservation property • Ensures that a constraint on the original relation can be maintained by simply enforcing some constraints on each of the smaller relations

  23. Normalization can be used to derive well-formed relations • We have various levels or steps in normalization called Normal Forms • The level of complexity, strength of the rule and decomposition increases as we move from one lower level Normal Form to the higher • A table in a relational database is said to be in a certain normal form if it satisfies certain constraints

  24. Normalization towards a logical design consists of the following steps: • UnNormalized Form: • Identify all data elements • First Normal Form: • Find the key with which you can find all data • Second Normal Form: • Remove part-key dependencies • Make all data dependent on the whole key • Third Normal Form • Remove non-key dependencies • Make all data dependent on nothing but the key • For most practical purposes, databases are considered normalized if they adhere to third normal form

  25. First Normal Form (1NF) • Requires that all column values in a table are atomic (e.g., a number is an atomic value, while a list or a set is not) • We have tow ways of achieving this: • Putting each repeating group into a separate table and connecting them with a primary key-foreign key relationship • Moving this repeating groups to a new row by repeating the common attributes. If so then Find the key with which you can find all data

  26. Definition: a table (relation) is in 1NF If • There are no duplicated rows in the table. Unique identifier • Each cell is single-valued (i.e., there are no repeating groups) • Entries in a column (attribute, field) are of the same kind • Second Normal Form (2NF) • No partial dependency of a non key attribute on part of the primary key • This will result in a set of relations with a level of Second Normal Form • Any table that is in 1NF and has a single-attribute (i.e., a non-composite) primary key is automatically in 2NF

  27. Definition: a table (relation) is in 2NF If • It is in 1NF and • If all non-key attributes are dependent on the entire primary key. i.e. no partial dependency • Third Normal Form (2NF) • Eliminate columns dependent on another non-primary Key • If attributes do not contribute to a description of the key, remove them to a separate table • This level avoids update and delete anomalies

  28. Definition: a table (relation) is in 3NF If • It is in 2NF and • There are no transitive dependencies between a primary key and non-primary key attributes • Generally, even though there are other four additional levels of Normalization, a table is said to be normalized if it reaches 3NF • A database with all tables in the 3NF is said to be Normalized database

More Related