ITM Chapter 4
Insertion - if new product is ordered for order 1007 of existing customer, customer data must be re-entered, causing duplication Deletion - if we delete the Dining Table from Order 1006, we lose information concerning this item's finish and price Update - changing the price of product ID 4 requires update in multiple records
Anomalies in This Relation
Data Structure Data Manipulation Data Integrity
Components of Relational Model
Use only their simple, component attributes
Composite attributes
-Relations (tables) correspond with entity types and with many-to-many relationship types. -Rows correspond with entity instances and with many-to-many relationship instances. -Columns correspond with attributes. NOTE: The word relation (in relational database) is NOT the same as the word relationship (in E-R model).
Correspondence with E-R Model
Mechanisms for implementing business rules that maintain integrity of manipulated data
Data Integrity
Powerful SQL operations for retrieving and modifying data
Data Manipulation
-Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of data -The process of decomposing relations with anomalies to produce smaller, well-structured relations
Data Normalization
Are identifiers that enable a dependent relation (on the many side of a relationship) to refer to its parent relation (on the one side of the relationship)
Foreign keys
The value of one attribute (the determinant) determines the value of another attribute
Functional Dependency
Goal is to avoid anomalies
Goal is to avoid anomalies
If we remove employee 140, we lose information about the existence of a Tax Acc class
Deletion
Deleting rows may cause a loss of data that would be needed for other future rows
Deletion Anomaly
Allowable values for an attribute (includes data types and restrictions on values)
Domain Constraints
No primary key attribute may be null. All primary key fields MUST contain data values
Entity Integrity
Are special fields that serve two main purposes
Key Fields
Set the foreign key in the dependent side to null if deleting from the parent side → not allowed for weak entities
Set-to-Null
•View Integration - Combining entities from multiple E-R models into common relations •Issues to watch out for when merging entities from different E-R models: -Synonyms - two or more attributes with different names but same meaning -Homonyms - attributes with same name but different meanings -Transitive dependencies - even if relations are in 3N F prior to merging, they may not be after merging -Supertype/subtype relationships - may be hidden prior to merging
Merging Relations
Giving a salary increase to employee 100 forces us to update multiple records
Modification
Changing data in a row forces changes to other rows because of duplication
Modification Anomaly
Becomes a separate relation with a foreign key taken from the superior entity
Multivalued Attribute
-Partial identifier of weak entity -Primary key of identifying relation (strong entity)
Primary key composed of
Are unique identifiers of the relation. Examples include employee numbers, social security numbers, etc. This guarantees that all rows are unique
Primary keys
-It must have a unique name. -Every attribute value must be atomic (not multivalued, not composite). -Every row must be unique (can't have two rows with exactly the same values for all their fields). -Attributes (columns) in tables must have unique names. -The order of the columns must be irrelevant. -The order of the rows must be irrelevant -All relations are in 1st Normal Form
Requirements for a table to qualify as a relation
-Don't allow delete of "parent" side if related rows exist in "dependent" side
Restrict
-1N F plus every non-key attribute is fully functionally dependent on the ENTIRE primary key -Every non-key attribute must be defined by the entire key, not by only part of the key -No partial functional dependencies
Second Normal Form
-A unique identifier. One of the candidate keys will become the primary key ▪E.g., perhaps there is both credit card number and SS# in a table...in this case both are candidate keys. -Each non-key field is functionally dependent on every candidate key.
Candidate Key
Automatically delete "dependent" side rows that correspond with the "parent" side row to be deleted
Cascade
Tables (relations), rows, columns
Data structure
•No multivalued attributes •Every attribute value is atomic •Fig. 4-25 is not in 1st Normal Form (multivalued attributes) → it is not a relation. •Fig. 4-26 is in 1st Normal form. •All relations are in 1st Normal Form.
First Normal Form
Rules that help ensure the quality of information
Integrity Constraints
Can't enter a new employee without having the employee take a class (or at least empty fields of class information)
Insertion
Adding new rows forces user to create duplicate data
Insertion Anomaly
Create a new relation with the primary keys of the two entities as its primary key
Many-to-Many
- Identifier Not Assigned • Default primary key for the association relation is composed of the primary keys of the two entities (as in M:N relationship) - Identifier Assigned • It is natural and familiar to end-users • Default identifier may not be unique
Mapping Associative Entities
Simple attributes Composite attributes Multivalued Attribute
Mapping Regular Entities to Relations
-One relation for supertype and for each subtype -Supertype attributes (including identifier and subtype discriminator) go into supertype relation -Subtype attributes go into each subtype; primary key of supertype relation also becomes primary key of subtype relation -1:1 relationship established between supertype and each subtype, with supertype as primary table
Mapping Supertype/Subtype Relationships
-One relation for each entity and one for the associative entity -Associative entity has foreign keys to each entity in the relationship
Mapping Ternary (and n-ary) Relationships
-One-to-Many - Recursive foreign key in the same relation -Many-to-Many - Two relations: ▪One for the entity type ▪One for an associative relation in which the primary key has two attributes, both taken from the primary key of the entity
Mapping Unary Relationships
Primary key on the one side becomes a foreign key on the many side
One-to-Many
Primary key on mandatory side becomes a foreign key on optional side
One-to-One
-Rules that maintain consistency between the rows of two related tables. -Rule states that any foreign key value (on the relation of the many side) MUST match a primary key value in the relation of the one side.(Or the foreign key can be null.)
Referential Integrity
A named two-dimensional table of data, consists of rows (records) and columns (attribute or field)
Relation
E-R attributes map directly onto the relation
Simple attributes
•2N F PLUS no transitive dependencies (functional dependencies on non-primary-key attributes) •Note: This is called transitive, because the primary key is a determinant for another attribute, which in turn is a determinant for a third •Solution: Non-key determinant with transitive dependencies go into a new table; non-key determinant becomes primary key in the new table and stays as foreign key in the old table
Third Normal Form
Relations that contain minimal data redundancy and allow users to insert, delete, and update rows without causing data inconsistencies
Well-Structured Relations
•Keys can be simple (a single field) or composite (more than one field). •Keys are usually used as indexes to speed up the response to user queries.
•Keys can be simple (a single field) or composite (more than one field). •Keys are usually used as indexes to speed up the response to user queries.
