Chapter 4 - Logical Database Design and the Relational Model Flashcards
Data structure ?
Table (relation), rows, columns
Data integrity ?
Mechanisms for implementing business rules that maintain integrity of manipulated data
What is a relation ?
A relation is a named, two dimensional table of data
Requirements for a table to qualify as a relation (6)
- Unique name
- Every attribute 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.
Correspondence with E-R Model :
- Relations (tables) correspond with __ and with __.
- Rows correspond with __ and __.
- Columns correspond with __.
- Note: The word relation (in __) is not
the same as the word relationship (in __).
- 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).
__ are unique identifiers of the relation.
Examples include employee numbers, social security
numbers, etc. This guarantees that __
Primary keys are unique identifiers of the relation.
Examples include employee numbers, social security
numbers, etc. This guarantees that all rows are unique.
__ are identifiers that enable a dependent
relation (on the __ of a relationship) to refer to its parent relation (on the __ of the relationship).
Foreign keys 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).
Keys can be _ (__) or __ (__).
Keys can be simple (a single field) or composite (more than one field).
Keys are usually used as __ to __ the response to user queries.
Keys are usually used as indexes to speed up the response to user queries.
Domain Constraints ?
Allowable values for an attribute (includes data types and restrictions on values)
Entity Integrity ?
No primary key attribute may be null. All primary key fields MUST contain data values.
Referential Integrity ?
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.)
Example of Referential Integrity ?
Delete Rules :
Restrict – don’t allow delete of “parent” side if related rows exist in “dependent” side
Cascade – automatically delete “dependent” side rows that correspond with the “parent” side row to be deleted
Set-to-Null – set the foreign key in the dependent side to null if deleting from the parent side → not allowed for weak entities
Mapping Regular Entities to Relations
– Simple attributes ?
– Composite attributes ?
– Multivalued attributes ?
Mapping Regular Entities to Relations
– Simple attributes: E-R attributes map directly onto the relation
– Composite attributes: Use only their simple,
component attributes
– Multivalued attributes: Become a separate relation
with a foreign key taken from the superior entity
Mapping Weak Entities
– Becomes a __ with a __ taken from the superior entity
– Primary key composed of ?
Mapping Weak Entities
– Becomes a separate relation with a foreign key taken from the superior entity
– Primary key composed of:
▪ Partial identifier of weak entity
▪ Primary key of identifying relation (strong entity)
Mapping Binary Relationships
– One-to-Many ?
– Many-to-Many ?
– One-to-One ?
Mapping Binary Relationships
– One-to-Many – Primary key on the one side becomes a foreign key on the many side
– Many-to-Many – Create a new relation with the primary keys of the two entities as its primary key
– One-to-One – Primary key on mandatory side becomes a foreign key on optional side
Mapping Associative Entities
– Identifier Not Assigned ?
– Identifier Assigned ?
Mapping Associative Entities
– 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 Unary Relationships
– One-to-Many ?
– Many-to-Many ?
Mapping Unary 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 Ternary (and n-ary) Relationships ?
Mapping Ternary (and n-ary) Relationships
– One relation for each entity and one for the
associative entity
– Associative entity has foreign keys to each entity in
the relationship
Mapping Supertype/Subtype Relationships ?
Mapping Supertype/Subtype Relationships
– 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
Data normalization ?
A tool to validate and improve a logical design so that it satisfies certain constraint that avoid uncecessary duplication of data. The process of decomposing relation with anomalies to produce smaller and well structured relation
Well structured relation ?
Relations that contains minimal data redundancy and allow users to insert, delete and update rows without causing data inconsistencies.
Insertion anomaly ?
Adding new rows forces user to create duplicate data
Deletion anomaly ?
Deleting rows may cause a loss of data that would be needed for other future rows
Modification anomaly ?
Changing data in a row forces changes to other rows because of duplication
Non relation to 1NF ?
Remove multivalued attributes
1NF to 2NF ?
Remove partial dependencies
2NF to 3NF ?
Remove transitive dependencies
3NF to Boyce-Codd normal form ?
Remove remaining anomalies resulting from multiple candidate keys
Boyce-Codd normal form to 4NF ?
Remove multivalued dependencies
4NF to 5NF ?
Remove remaining anomalies
Functional Dependency ?
The value of one attribute (the determinant) determines the value of another attribute
Candidate key ?
- A unique identifier. One of the candidate keys will become the primary key
- Each non-key field is functionally dependent on every candidate key.