Database Lesson #2 of 8 - The Relational Model

Database Lesson #2 of 8 - The Relational Model

Introduction to the Relational Model

In this section, the instructor introduces the topic of the relational model and outlines the objectives for this lecture.

Conceptual Foundations of the Relational Model

  • The relational model is a fundamental concept in database design and management.
  • Understanding the differences between a relation and a regular table is important.
  • Terminology associated with the relational model will be introduced.
  • Keys play a significant role in the relational model, and different types of keys will be explored.

Implementing Relationships with Foreign Keys

  • Foreign keys are used to establish relationships between tables within the relational model.
  • The lecture will cover how foreign keys are used to implement these relationships.

Normalization and Dependencies

  • The lecture will touch upon normalization, which is an important process in database design.
  • Normalization will be discussed in the context of dependencies.
  • The process for normalizing relations will be introduced.

Entities in Database Design

This section focuses on entities and their significance in database design.

Definition of an Entity

  • An entity represents something important that we want to store information about in a database.
  • An entity should represent a single theme or business concept, such as an employee or department.
  • Information about entities is stored using attributes.

Relations (Tables) in Database Design

This section explains what relations (tables) are and their characteristics within the relational model.

Definition of a Relation

  • A relation is a specific type of table within the relational model.
  • Certain conditions must be met for a table to qualify as a relation:
  • Rows contain information about instances of an entity.
  • Columns represent attributes of the entity.
  • Cells in the table can only hold a single value.
  • Values within a specific column must be of the same data type.
  • Every column must have a unique name.
  • No two rows within the table can be identical.
  • The order of rows and columns does not matter.

Example of a Relation

  • A sample relation (table) is shown with three columns: EmployeeNumber, FirstName, and LastName.
  • Each row represents a single employee, meeting all the characteristics of a relation.

Characteristics of Relations

This section further explores the characteristics that define relations (tables) within the relational model.

Single Value Cells

  • In order for a table to qualify as a relation, cells in the table can only hold a single value.
  • Storing more than one value in the same cell is not allowed.

Same Data Type for Column Values

  • All values within a specific column must be of the same data type.
  • For example, if an Employee ID column uses an integer data type, all values in that column must be integers.

Unique Column Names

  • Every column in a relation must have a unique name.
  • This ensures clarity when making requests to the database management system.

Uniqueness of Rows

  • No two rows within a relation can be identical when considering all values in the row together.

Sample Relation Analysis

This section analyzes an example relation (table) to illustrate its characteristics.

Analyzing an Example Relation

  • An example table with three columns (EmployeeNumber, Phone, LastName) is shown.
  • This table does not qualify as a relation due to several problems:
  • The values stored...

Understanding Relations and Tables

In this section, we learn about the concept of relations and tables in the context of databases. We explore the uniqueness requirement for rows in a table and discuss synonyms used for tables, relations, and files.

Uniqueness Requirement for Rows

  • Each row in a table must have something unique about it.
  • No two rows can be identical to each other.
  • If all values for a row are considered together, there must be uniqueness.

Relations vs Tables

  • All relations are tables, but not all tables are relations.
  • Different textbooks or database managers may use different words like table, relation, or file to refer to the same concept.

Synonyms in Database Vocabulary

  • Different terms may be used interchangeably in the database world.
  • Examples include table/relation/file and row/record/tuple.
  • The horizontal data structure within a table can also be referred to as a column/field/attribute.
  • The vertical data structure within a table is called a column/field/attribute.

Keys in Relational Model

This section introduces the concept of keys in the relational model. We learn that keys are columns used to identify rows and come in different varieties such as unique and non-unique keys.

Definition of Keys

  • A key is a column within a relation that is used to identify a row.
  • Keys can be unique or non-unique.

Unique Keys

  • Unique keys have values that are unique within the entire table.
  • For example, an employee ID column where no two employees can have the same ID.

Non-Unique Keys

  • Non-unique keys allow multiple rows to have the same value for that key column.
  • They are often used to categorize rows into groups based on common attributes like department ID.

Dan's Typology of Database Keys

In this section, we explore different types of keys in the database world according to Dan's Typology. We discuss unique and non-unique keys, including foreign keys, candidate keys, composite keys, primary keys, and surrogate keys.

Unique Keys

  • Unique keys are subdivided into two major groups: unique and non-unique.
  • Foreign key is a type of non-unique key.
  • Several types of unique keys include candidate keys, composite keys, primary keys, and surrogate keys.

Composite Keys

  • A composite key is a unique key composed of two or more columns.
  • The values of these columns are combined to achieve uniqueness.
  • An example is combining flight number and date to uniquely identify flights in an airline table.

Using Composite Keys for Uniqueness

This section explains the concept of using composite keys for achieving uniqueness in a table. An example with flight numbers and dates is used to illustrate this concept.

Achieving Uniqueness with Composite Keys

  • Combining multiple columns can create a composite key for achieving uniqueness.
  • For example, combining flight number and date can uniquely identify flights within a table.
  • This approach ensures that even if individual columns have duplicate values, the combination will be unique.

Conclusion

The video concludes by emphasizing the importance of understanding relations and tables in databases. It highlights the significance of uniqueness requirements for rows and introduces the concept of database keys as identifiers for rows.

New Section

In this section, the concept of primary keys and candidate keys in database design is discussed.

Primary Key

  • A primary key is chosen as the main identifier for a relation.
  • It is a unique key that allows us to locate a specific single row within the table.
  • Example: An employee relation with an Employee ID column as the primary key.

Surrogate Key

  • A surrogate key is a unique key intentionally added as a new column to serve as the primary key.
  • It is often used when there is no natural column that can be used as a unique identifier.
  • Example: Using an EmployeeNumber column as a surrogate key in an employee table.

New Section

This section explains how surrogate keys are used to avoid using composite primary keys in tables.

Composite Primary Key

  • A composite primary key consists of multiple columns combined together to create uniqueness.
  • Example: Combining Flight Number and Date columns in an airline flight table.

Surrogate Key Usage

  • Surrogate keys are used when there is no meaningful natural column that can serve as a unique identifier.
  • They help avoid using composite primary keys and simplify data management.
  • Example: Adding a Flight ID column as a surrogate key in an airline flight table.

New Section

This section introduces the concept of foreign keys and their role in establishing relationships between tables.

Business Relationships

  • In the business world, relationships exist among different business objects or concepts.
  • Examples: Employees working in departments, projects being assigned project managers.

Foreign Keys

  • Foreign keys are used to establish relationships between tables by linking records through matched pairs of values.
  • A foreign key is a primary key from one table added into another table for linking purposes.
  • Example: Adding Manager ID as a foreign key in the Project table to link with the Manager table.

New Section

This section explains how foreign keys enable the retrieval of related information from linked tables.

Retrieving Related Information

  • Foreign keys allow us to easily determine related information by using the primary key value from one table to look up data in another table.
  • Example: Using Manager ID in the Project table to retrieve the name of the manager from the Manager table.

Enforcing Referential Integrity

  • Referential integrity ensures that each value of a foreign key matches an existing primary key value.
  • The database management system enforces referential integrity to maintain data quality.
  • Example: Ensuring that each project's Manager ID in the Project table corresponds to an existing Manager ID in the Manager table.

Understanding Foreign Keys and Null Values

In this section, the speaker discusses the concepts of foreign keys and null values in a database.

Foreign Keys

  • A foreign key is a field in one table that refers to the primary key in another table.
  • It establishes a relationship between two tables.
  • The customer ID in the project table acts as a foreign key, while the customer ID in the customer table is the primary key.
  • Multiple rows in the project table can have the same customer ID, indicating association with a specific customer.
  • Foreign keys are non-unique keys, meaning multiple rows can have the same value for a foreign key.

Null Values

  • A null value represents an empty cell or no data within a particular cell.
  • It is different from zero, space character, empty string, or any other character.
  • Null values can be ambiguous as they can potentially mean different things.
  • They may indicate that the proper value has not yet been determined or that it is simply not known or missing.

Functional Dependencies and Relational Model

This section covers functional dependencies and their role in designing data structures using the relational model.

Functional Dependencies

  • Functional dependency is a relationship between attributes within a table where one attribute's value determines other attribute values.
  • For example, knowing the price per cookie and quantity allows us to determine the price of a box of cookies. The cookie price and quantity are determinants that determine the box price.

Characteristics of Relational Model

  • Candidate keys functionally determine all non-key attributes in a row.
  • Primary keys must also functionally determine all non-key attributes in a row.
  • Knowing an EmployeeID should allow us to find associated attributes like employee last name and phone number within an employee relation.
  • Similarly, knowing ProjectID should help find attributes like project name and start date within a project relation.

Data Normalization

This section introduces the concept of data normalization and its importance in creating well-formed relations.

Data Normalization

  • Data normalization is a process used by database designers to determine if a relation is well formed.
  • A well-formed relation is not susceptible to deletion, update, or insertion anomalies.
  • The normalization process helps minimize or eliminate empty cells within tables.
  • Further details about data normalization will be covered in future lectures.

The transcript provided does not include timestamps for all sections.

Well-Formed Relations and Candidate Keys

In this section, the speaker discusses the concept of well-formed relations and candidate keys in database design.

Well-Formed Relations

  • A relation is considered well-formed if every determinant within the relation is also a candidate key.
  • Determinants are attributes that determine other attributes in a relation.
  • Every determinant must be a candidate for promotion to the status of primary key.

Breaking Apart Relations

  • If a relation is not well-formed, it needs to be broken apart into smaller relations to make them well-formed.
  • The goal is to create smaller relations that adhere to the principles of well-formedness.

Single Business Concept Rule

  • A well-formed relation should encompass only a single business concept.
  • If a relation contains non-key attributes for more than one business concept, it is likely not well-formed.
  • In such cases, breaking the relation into smaller relations is necessary for successful normalization.

Designing Well-Formed Relations

This section provides tips on designing well-formed relations in database design.

Tip: Single Business Concept Rule

  • As a general rule, a well-formed relation should not encompass more than a single business concept.
  • If a relation contains non-key attributes for multiple business concepts, it is likely not well-formed and needs to be broken down into smaller relations.

Examples of Breaking Apart Relations

This section presents examples illustrating how to break apart relations into smaller, well-formed relations.

Example 1: Student and Dorm Relation

  • In this example, we have a StudentID as the determinant attribute.
  • The original relation includes attributes like StudentName, DormName, and DormCost.
  • If DormCost can be determined by DormName alone, we need to break the relation into two smaller relations.
  • Student relation: Contains StudentID (primary key), StudentName, and DormName (foreign key).
  • Dorm table: Contains DormName (primary key) and DormCost (non-key attribute).

Example 2: Attorney and Client Meeting Relation

  • In this example, we need to record meetings between an attorney and a client.
  • The original relation includes attributes like AttorneyID, ClientID, MeetingDate, and Duration.
  • If the client name can be separately determined by ClientID, we should remove it from the original relation.
  • Resulting table: Contains AttorneyID, ClientID, MeetingDate, and Duration. AttorneyID and ClientID together determine MeetingDate and Duration.
  • Second table: Contains ClientID (primary key) and ClientName.

Data Normalization Process

This section explains the steps involved in ensuring a relation is well-formed through data normalization.

Objective: Third Normal Form

  • The objective of the data normalization process is to reach third normal form for our data tables.
  • To achieve this, we need to first normalize our tables into first normal form, then second normal form before reaching third normal form.

Higher Normal Forms

  • There are higher normal forms beyond third normal form (e.g., fourth normal form, fifth normal form).
  • However, for most business data needs, third normal form is sufficient.

First Normal Form

This section defines first normal form in database design.

Definition of First Normal Form

  • A relation is in first normal form if it does not contain any multivalued attributes.
  • Every attribute value within the table must be atomic; no more than one value should be stored in each cell of the table.

All Relations Are in First Normal Form

  • By definition, all relations are in first normal form.
  • If a table meets the definition of a relation, it is also in first normal form.

Example of First Normal Form

This section provides an example to illustrate first normal form.

Table Not in First Normal Form

  • The example shows a table that is not in first normal form.
  • The table contains multivalued attributes, with multiple values stored in each cell for certain columns.
  • Due to the presence of multivalued attributes, this table cannot be considered a relation.

Second Normal Form

This section explains second normal form and its requirements.

Requirements for Second Normal Form

  • To qualify as being in second normal form, a table must meet all the criteria of first normal form.
  • Additionally, every non-key attribute within the table must be fully functionally dependent upon the entire primary key.

Conclusion

In this transcript, we learned about well-formed relations and candidate keys. We explored examples of breaking apart relations to achieve well-formedness. Additionally, we discussed the data normalization process and the importance of reaching third normal form. Finally, we covered first and second normal forms and their respective requirements.

Understanding Composite Primary Keys

In this section, we learn about composite primary keys and their role in uniquely identifying rows within a table.

Composite Primary Key

  • A composite primary key is made up of multiple attributes.
  • In the given example, the composite primary key consists of Order_ID and Product_ID.
  • The combination of an Order_ID value and a Product_ID value should be able to uniquely identify every row within the table.

Partial Dependencies in Tables

This section discusses partial dependencies within tables and how they can affect normalization.

Partial Dependencies

  • Partial dependencies occur when non-key attributes depend on only part of the primary key.
  • In the given example, attributes like Product_Description, Product_Finish, and Unit_Price are dependent on Product_ID but not on the entire primary key.
  • This creates partial dependencies as these values do not require both Order_ID and Product_ID to be known.

Moving from First Normal Form to Second Normal Form

Here we explore the process of moving from first normal form to second normal form by eliminating partial dependencies.

Breaking Relations Apart

  • To move from first normal form to second normal form, we need to break apart relations into smaller ones.
  • The original relation is broken into three separate relations: ORDER_LINE, PRODUCT, and CUSTOMER_ORDER.

Removing Partial Dependencies for Second Normal Form

This section explains how breaking relations apart helps remove partial dependencies for achieving second normal form.

Fully Functional Dependencies

  • By breaking the original relation into smaller relations, all non-key attributes become fully functionally dependent on the entire primary key.
  • For example, in the PRODUCT relation, knowing the Product_ID allows us to determine the Product_Description, Product_Finish, and Unit_Price.

Transitive Dependencies and Third Normal Form

Here we discuss transitive dependencies and their impact on achieving third normal form.

Transitive Dependencies

  • A transitive dependency occurs when a non-key attribute depends on another non-key attribute.
  • In order to achieve third normal form, all transitive dependencies must be eliminated.

Breaking Relations for Third Normal Form

This section explains how breaking relations apart helps eliminate transitive dependencies for achieving third normal form.

Eliminating Transitive Dependency

  • To remove a transitive dependency, we break the relation into smaller relations.
  • In this case, the CUSTOMER_ORDER relation is broken into two separate relations: ORDER and CUSTOMER.
  • Both of these relations are now in third normal form as they contain no partial or transitive dependencies.

Achieving a Relational Model in Third Normal Form

This section highlights the importance of designing relations that are in third normal form.

Creating Relations in Third Normal Form

  • From the original relation, four separate relations are created to achieve a relational model in third normal form: ORDER_LINE, PRODUCT, CUSTOMER, and ORDER.
  • Each relation contains attributes related to one specific business concept or theme.
  • Designing relations in third normal form ensures data integrity and reduces redundancy.

Conclusion and Practice

The conclusion emphasizes the importance of practice in understanding normalization concepts and designing relations in third normal form.

Mastering Normalization

  • With practice, normalization concepts will become second nature.
  • The key point to remember is that each relation should contain attributes related to one and only one business concept or theme.
  • By following this rule, it becomes easier to create relations that are in third normal form.
Video description

Dr. Soper gives a lecture on the relational model and its role in the database world. Topics include relations, primary keys, composite keys, foreign keys, normal forms, and the normalization process.