Author: saqibkhan

  • Difference Between 4NF and 5NF

    Normalization is an essential part of designing efficient and reliable databases. Most discussions focus on the first three normal forms and Boyce-Codd Normal Form (BCNF), however the journey does not stop there. The Fourth Normal Form (4NF) and the Fifth Normal Form (5NF) take normalization to even higher levels. 4NF and 5NF address specific types of dependencies like multivalued and join dependencies. Read this chapter to understand these advanced normal forms in detail.

    What is Fourth Normal Form (4NF)?

    The fourth normal form helps in eliminating multivalued dependencies from a database table. A multivalued dependency occurs when two attributes are independent of each other but depend on a third attribute. For instance, if one value in a table implies multiple rows, then there may be redundancy caused by multivalued dependencies.

    Rules of 4NF

    For a table to satisfy 4NF −

    • It must already be in Boyce-Codd Normal Form (BCNF).
    • The table must not have more than one multivalued dependency.

    What is Multivalued Dependency?

    If A →→ B (A multi-determines B), this means for a single value of A, there can be multiple values of B. But B is independent of any other attribute.

    Example: Multivalued Dependency in Action

    Consider a table that stores information about a Person, their Mobile Numbers, and their Food Preferences −

    PersonMobileFood_Likes
    Mahesh9893Burger
    Mahesh9424Pizza
    Ramesh9191Pizza

    Here −

    • Person →→ Mobile
    • Person →→ Food_Likes

    Both Mobile and Food_Likes are independent of each other, however they depend on Person. This results in redundancy because the same Person is repeated unnecessarily for each Mobile and Food_Likes.

    Normalizing a Table to 4NF

    To bring this table into 4NF, we can separate the dependencies into two tables −

    Table 1 − Person-Mobile

    PersonMobile
    Mahesh9893
    Mahesh9424
    Ramesh9191

    Table 2 − Person-Food_Likes

    PersonFood_Likes
    MaheshBurger
    MaheshPizza
    RameshPizza

    By decomposing the table, we eliminate redundancy. And each table is now in 4NF.

    What is Fifth Normal Form (5NF)?

    After 4NF, we must understand the concept of Fifth Normal Form, which is also known as the Projected Normal Form (PJNF). It addresses the join dependencies.

    join dependency exists when a table can be split into two or more tables. And the original table can be reconstructed by joining them without any data loss. In 5NF, every join dependency must be implied by the table’s candidate keys.

    Rules of 5NF

    For a table to satisfy 5NF −

    • It must already be in 4NF.
    • It must not contain any join dependency that cannot be implied by its candidate keys.

    What is Join Dependency?

    join dependency occurs when a table can be decomposed into smaller tables, but joining those smaller tables recreates the original table without any data loss or spurious rows.

    Example: Join Dependency in Action

    Let us consider a table that stores the data on Agents, the Companies they work with, and the Products they sell.

    AgentCompanyProduct
    A1PQRNut
    A1PQRBolt
    A1XYZNut
    A1XYZBolt
    A2PQRNut

    Here, if an Agent works with a Company and the Company sells a particular Product, then the Agent is assumed to sell that product.

    Normalizing a Table to 5NF

    To eliminate the join dependency, we decompose the table into three smaller tables −

    Table 1 − Agent-Company

    AgentCompany
    A1PQR
    A1XYZ
    A2PQR

    Table 2 − Company-Product

    CompanyProduct
    PQRNut
    PQRBolt
    XYZNut
    XYZBolt

    Table 3 − Agent-Product

    AgentProduct
    A1Nut
    A1Bolt
    A2Nut

    When these three tables are again joined back using their shared attributes (Company and Product), the original table is reconstructed without any spurious data.

    Comparing 4NF and 5NF

    The following table highlights how 4NF differs from 5NF −

    Aspect4NF5NF
    Dependency TypeMultivalued DependencyJoin Dependency
    PurposeEliminates redundancy from multivalued dependencies.Ensures lossless decomposition of join dependencies.
    Example ScenarioPerson with multiple phones and food preferences.Agent, company, and product relationships.

    Practical Considerations in Using 4NF and 5NF

    Although 4NF and 5NF provide the highest levels of normalization, they are used quite rarely. 4NF and 5NF are not always necessary for every database. because −

    • Complexity − Splitting the tables into smaller parts can make the database structure more complicated.
    • Performance − Highly normalized databases might require more joins, which may slow down the query performance.
    • Use Cases − Applications with simpler data relationships often do not need to go beyond BCNF or 4NF.

    However, when it is paramount to maintain accuracy and avoid any sort of data redundancy (while maintaining financial or scientific databases, for example), it becomes a necessity to normalize the tables to 4NF and 5NF.

  • Boyce-Codd Normal Form (BCNF) in DBMS

    The Third Normal Form (3NF) eliminates many redundancy issues, but still there are cases where 3NF is not strict enough. In such cases, we have to apply the Boyce-Codd Normal Form (BCNF), which is also known as 3.5NF.

    BCNF is a more restrictive version of 3NF that addresses potential anomalies. Read this chapter to understand the basic concepts of BCNF, its rules, and how to apply it in practice.

    What is Boyce-Codd Normal Form?

    The Boyce-Codd Normal Form (BCNF) is a special case of 3NF. As we know in 3NF, it allows some flexibility with non-prime attributes and functional dependencies. The BCNF tightens the rules. It ensures that every functional dependency in a table adheres to stricter conditions.

    Rules of Boyce-Codd Normal Form

    For a table to be in BCNF they must follow the following rules −

    • The table must be in 3NF.
    • For every functional dependency, the left-hand side (LHS) must be a candidate key or super key.

    In 3NF we know that there will be no transitive dependency. Where the RHS can be a prime attribute to satisfy the rule. In BCNF it demands that the LHS always includes a candidate key. This eliminates any chance of redundancy caused by improper dependencies.

    Understanding BCNF with an Example

    Let us consider the following Student table −

    Roll NumberNameVoter IDAge
    1JohnV00120
    2AliceV00222
    3BobV00321

    The table has the following candidate keys and functional dependencies −

    • Candidate Keys − Roll Number and Voter ID (each uniquely identifies a row).
    • Functional Dependencies −
      • Roll Number → Name
      • Roll Number → Voter ID
      • Voter ID → Age
      • Voter ID → Roll Number

    Checking Each Dependency against BCNF

    Now let us analyze each functional dependency step by step and check whether the table is BCNF compliant.

    Roll Number → Name −

    • LHS (Roll Number) is a candidate key.
    • This dependency is valid under BCNF.

    Roll Number → Voter ID −

    • Again, the LHS is a candidate key, so it satisfies BCNF.

    Voter ID → Age −

    • LHS (Voter ID) is also a candidate key.
    • This is valid under BCNF.

    Voter ID → Roll Number −

    • Here, the LHS is a candidate key (Voter ID), making it compliant with BCNF.

    Since all the functional dependencies have a candidate key or super key on the LHS, this table is in BCNF.

    Importance of Boyce-Codd Normal Form

    BCNF eliminates anomalies that might persist even in 3NF. For instance −

    • Redundancy − A non-prime attribute depending on something other than the candidate key can lead to duplicate data.
    • Update Anomalies − Incorrect updates to redundant data might create inconsistencies.
    • Deletion Anomalies − Removing a record could unintentionally delete important relationships.

    BCNF Compared to Other Normal Forms

    Let us compare BCNF with the normal forms that we have discussed so far −

    First Normal Form (1NF)Ensures no multi-valued attributes.Every cell must contain atomic values.
    Second Normal Form (2NF)Builds on 1NF.Eliminates partial dependencies.
    Third Normal Form (3NF)Builds on 2NF.Eliminates transitive dependencies.Allows non-prime attributes on the RHS if the LHS is a candidate key or super key.
    Boyce-Codd Normal Form (BCNF)Builds on 3NF.No exceptions: the LHS of every functional dependency must be a candidate key or super key.

    Relationship between Normal Forms

    The following diagram shows how the different Normal Forms are related −

    Boyce-Codd Normal Form1

    BCNF is the most restrictive form, sitting inside 3NF. 3NF sits inside 2NF and 2NF sits inside 1NF. This hierarchy means every table in BCNF is also in 3NF. However, not every table in 3NF is necessarily in BCNF.

    Another Example: BCNF in Practice

    Consider a relation {A, B, C, D} with these functional dependencies −

    • AB → C
    • C → D

    Step 1: Identify the Candidate Keys

    • From AB → C, we see AB is a candidate key because it determines C.
    • From C → D, we can derive AB → D via transitivity, so AB determines all attributes.

    Step 2: Check Each Dependency

    AB → C −

    • LHS is a candidate key.
    • Satisfies BCNF.

    C → D −

    • LHS (C) is not a candidate key.
    • Violates BCNF because C is a non-prime attribute.

    Step 3: Split the Table

    To satisfy BCNF, we split the table into two −

    Table 1 − {AB → C}

    Boyce-Codd Normal Form2

    Table 2 − {C → D}

    Boyce-Codd Normal Form3

    BCNF – Key Points to Note

    Make a note of the following key points on BCNF –

    • Stricter than 3NF − BCNF removes any dependency where the LHS is not a candidate key.
    • No Exceptions − While 3NF allows non-prime attributes on the RHS, BCNF does not tolerate them unless the LHS is a candidate key.
    • Requires Splitting − Many tables in 3NF need to be split further to achieve BCNF.
  • Third Normal Form (3NF) in DBMS

    Once a table meets the requirements of Second Normal Form (2NF), the next step is to convert it into Third Normal Form (3NF). This is used to eliminate transitive dependency. Read this chapter to get a clear understanding of 3NF and transitive dependency.

    What is Third Normal Form (3NF)?

    In relational database, the third normal form has two certain conditions −

    • The table is already in Second Normal Form (2NF).
    • The table does not have any transitive dependency.

    What is Transitive Dependency?

    A transitive dependency occurs when a non-prime attribute depends on another non-prime attribute rather than directly depending on a candidate key.

    To put it simply, in a transitive dependency, one non-prime attribute is indirectly connected to the candidate key through another non-prime attribute. This will may make unnecessary redundancy and inconsistency in the data.

    To understand this better, let us elaborate some of the important terms −

    • Candidate Key − A minimal set of attributes that uniquely identify each row in the table.
    • Prime Attribute − An attribute that is part of a candidate key.
    • Non-Prime Attribute − An attribute that is not part of any candidate key.

    Example of Transitive Dependency

    Consider the Student table with the following data

    Roll NumberStateCity
    1PunjabMohali
    2PunjabLudhiana
    3KarnatakaBangalore
    4MaharashtraMumbai

    The Functional Dependencies are −

    • Roll Number → State
    • State → City

    In this example, the candidate key is the Roll Number because it uniquely identifies each row. State and City are non-prime attributes.

    Third Normal Form1

    The Roll Number determines the State. And, the State determines the City. It creates a transitive dependency. Here, the Roll Number indirectly determines the City through the State.

    While “Roll Number → State” is valid, this dependency “State → City” violates 3NF because it is a relationship between two non-prime attributes.

    How to Eliminate Transitive Dependency?

    To remove transitive dependency, we need to split the table into smaller tables or decomposition.

    Step 1: Divide the Table

    We create two separate tables: one table links the candidate key to the first non-prime attribute (State), and the other table links the first non-prime attribute (State) to the second non-prime attribute (City).

    Third Normal Form2

    Step 2: Identify the Keys

    In the Student Table, the candidate key remains Roll Number. The State is a non-prime attribute. In the State Table, the primary key is State, but we can see there are duplicate States. So, we can add another key attribute called state id, and that can be used inside the Student table as well.

    By splitting the table, we can ensure that all non-prime attributes directly depend on the candidate key or are part of a separate table where they follow the same rule.

    Another Example of 3NF: Table and Functional Dependencies

    Consider a relation {A, B, C, D} with the following dependencies −

    • AB → C
    • C → D

    Step 1: Identify the Candidate Key

    To find the candidate key −

    • AB → C means AB determines C.
    • C → D means C determines D.

    From AB, we can easily determine all the attributes: {AB → C → D}. So, the candidate key is {AB}.

    Step 2: Classify the Attributes

    Next, let’s classify the attributes −

    • Prime Attributes − A, B (since they form the candidate key).
    • Non-Prime Attributes − C, D.

    Step 3: Check for Transitive Dependency

    • AB → C: This is valid because the candidate key determines a non-prime attribute.
    • C → D: This creates a transitive dependency since:
    • D is a non-prime attribute.
    • D is determined by another non-prime attribute (C).

    Step 4: Eliminate Transitive Dependency

    Split the table into two −

    Third Normal Form3

    Now,

    • In the Main Table, AB is the candidate key and C is a non-prime attribute directly dependent on it.
    • In the Derived Table, C is the candidate key and D depends directly on it.

    How to Check for 3NF Compliance

    To determine if a table is in 3NF, follow the steps give below –

    • Ensure the Table is in 2NF − No partial dependency should exist.
    • Check Functional Dependencies − For each dependency, ensure that either:
      • The left-hand side (LHS) is a candidate key or super key, or
      • The right-hand side (RHS) is a prime attribute.

    A quick rule of thumb − if a non-prime attribute depends on another non-prime attribute, it is a transitive dependency. This is violating 3NF.

    Practical Steps to Achieve 3NF

    Follow the steps given below to turn a table into its Third Normal Form –

    • Find the Candidate Keys − Use closure methods to identify all the candidate keys.
    • Classify the Attributes − Divide the attributes into prime and non-prime categories.
    • Check the Dependencies − If the LHS of a functional dependency is not a candidate key or super key, check if the RHS is a prime attribute.
    • Eliminate the Transitive Dependencies − Split the table into smaller ones if necessary.
  • Second Normal Form (2NF) in DBMS

    Normal Forms ensure that the data in the tables remain structured and efficient. After achieving First Normal Form (1NF), the next step in normalization is the Second Normal Form (2NF) that helps eliminate certain types of redundancy by addressing partial dependency. Read this chapter to learn in detail what is 2NF and how it is applied.

    What is Second Normal Form (2NF)?

    The rules for 2NF are straightforward. According to E. F. Codd, the father of relational databases,

    • The table must already be in First Normal Form (1NF).
    • There should be no partial dependency in the table.

    Let’s break down these rules further −

    • 1NF Requirement − It means the table should not have multi-valued attributes. Each cell should have one and only one value.
    • No Partial Dependency − A partial dependency occurs when a non-prime attribute depends on only a part of a composite candidate key; not only on the entire key.

    To understand this better, let us elaborate some of the important terms −

    • Candidate Key − A minimal set of attributes that can uniquely identify each row.
    • Prime Attributes − Attributes that are part of a candidate key.
    • Non-Prime Attributes − Attributes that are not part of any candidate key.

    What is Partial Dependency?

    partial dependency exists when a non-prime attribute is dependent on just a part of a composite candidate key. It creates redundancy and anomalies in the database.

    Example of Partial Dependency

    Let’s consider the following table −

    Customer IDStore IDLocation
    11Delhi
    21Delhi
    32Bangalore
    43Mumbai

    In this case,

    • Candidate Key − The combination of Customer ID and Store ID uniquely identifies each row.
    • Prime Attributes − Customer ID, Store ID
    • Non-Prime Attribute − Location

    If we look closely, the attribute “Location” is dependent only on “Store ID”. For example, wherever Store ID is 1, the location is Delhi. It violates the second rule of 2NF because Location does not depend on the entire composite key (Customer ID, Store ID).

    How to Convert a Table to 2NF?

    Whenever a table violates 2NF, the solution is to split it into smaller tables. We call this process “Decomposition“. Let us see how it works with the above example.

    Step 1: Divide the Table

    We break the table into two smaller tables −

    • One table stores the composite key along with its prime attributes.
    • Another table stores the partial dependency.
    Second Normal Form1

    Step 2: Identify the Keys

    • In the Customer Table, the candidate key remains Customer ID, Store ID.
    • In the Store Table, the primary key is Store ID.

    Now, the non-prime attribute Location depends fully on the candidate key of its table (Store ID). This is ensuring that both tables are in 2NF.

    General Steps for Achieving 2NF

    Given below are the general steps to make any table comply with 2NF −

    • Identify the Candidate Key − Use functional dependencies to find all possible candidate keys.
    • Classify the Attributes − Prime attributes are part of the candidate key. Non-prime attributes are everything else.
    • Check for Partial Dependencies − If any non-prime attribute depends on only part of a composite candidate key. It is a partial dependency.
    • Split the Table − Create separate tables to resolve partial dependencies.

    Another Example: Functional Dependency

    Let us explore a more complex example with functional dependencies.

    Table and Functional Dependencies

    We have a relation: {A, B, C, D, E, F} with these dependencies −

    • C → F
    • E → A
    • E, C → D
    • A → B

    Step 1: Identify the Candidate Key

    To find the candidate key, we must look at the right-hand side (RHS) of the functional dependencies: {F, A, D, B}. Attributes not on the RHS (E and C) must be part of the candidate key.

    Start with E, C −

    • E → A
    • C → F
    • E, C → D
    • A → B

    Thus, the closure of E, C covers all attributes: {E, C, A, F, D, B}. So, the candidate key is {E, C}.

    Step 2: Prime and Non-Prime Attributes

    • Prime Attributes − E, C.
    • Non-Prime Attributes − A, B, D, F.

    Step 3: Check for Partial Dependencies

    partial dependency occurs when −

    • The left-hand side (LHS) of a functional dependency is a proper subset of the candidate key.
    • The RHS is a non-prime attribute.

    In our example,

    • C → F: C is a proper subset of {E, C}, and F is non-prime. Partial dependency exists.
    • E → A: E is a proper subset of {E, C}, and A is non-prime. Partial dependency exists.

    Step 4: Split the Table

    In this step, to eliminate partial dependencies, we divide the table into smaller tables −

    Second Normal Form2

    The derived tables are given below –

    Second Normal Form3

    Each table satisfies 2NF because all non-prime attributes fully depend on the candidate key of their respective tables.

    Key Concepts in 2NF

    Following are the key concepts in 2NF –

    • Prime Attribute − Part of a candidate key.
    • Non-Prime Attribute − Not part of any candidate key.
    • Partial Dependency − A non-prime attribute depends on part of a composite candidate key.
    • Full Functional Dependency − A non-prime attribute depends on the entire candidate key.

    Conclusion

    In this chapter, we explained in detail the concept of Second Normal Form (2NF) and how to address partial dependency in relational databases. We started with the basic rules of 2NF, highlighting the importance of achieving 1NF first.

    Through detailed examples, we explored the concept of partial dependency and demonstrated how to split tables into smaller ones to remove redundancy. By ensuring 2NF, we make the databases more efficient by reducing the data redundancy and setting the stage for higher levels of normalization.

  • Normalization

    Functional Dependency

    Functional dependency (FD) is a set of constraints between two attributes in a relation. Functional dependency says that if two tuples have same values for attributes A1, A2,…, An, then those two tuples must have to have same values for attributes B1, B2, …, Bn.

    Functional dependency is represented by an arrow sign (→) that is, X→Y, where X functionally determines Y. The left-hand side attributes determine the values of attributes on the right-hand side.

    Armstrong’s Axioms

    If F is a set of functional dependencies then the closure of F, denoted as F+, is the set of all functional dependencies logically implied by F. Armstrong’s Axioms are a set of rules, that when applied repeatedly, generates a closure of functional dependencies.

    • Reflexive rule − If alpha is a set of attributes and beta is_subset_of alpha, then alpha holds beta.
    • Augmentation rule − If a → b holds and y is attribute set, then ay → by also holds. That is adding attributes in dependencies, does not change the basic dependencies.
    • Transitivity rule − Same as transitive rule in algebra, if a → b holds and b → c holds, then a → c also holds. a → b is called as a functionally that determines b.

    Trivial Functional Dependency

    • Trivial − If a functional dependency (FD) X → Y holds, where Y is a subset of X, then it is called a trivial FD. Trivial FDs always hold.
    • Non-trivial − If an FD X → Y holds, where Y is not a subset of X, then it is called a non-trivial FD.
    • Completely non-trivial − If an FD X → Y holds, where x intersect Y = Φ, it is said to be a completely non-trivial FD.

    Normalization

    If a database design is not perfect, it may contain anomalies, which are like a bad dream for any database administrator. Managing a database with anomalies is next to impossible.

    • Update anomalies − If data items are scattered and are not linked to each other properly, then it could lead to strange situations. For example, when we try to update one data item having its copies scattered over several places, a few instances get updated properly while a few others are left with old values. Such instances leave the database in an inconsistent state.
    • Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of unawareness, the data is also saved somewhere else.
    • Insert anomalies − We tried to insert data in a record that does not exist at all.

    Normalization is a method to remove all these anomalies and bring the database to a consistent state.

    First Normal Form

    First Normal Form is defined in the definition of relations (tables) itself. This rule defines that all the attributes in a relation must have atomic domains. The values in an atomic domain are indivisible units.

    unorganized relation

    We re-arrange the relation (table) as below, to convert it to First Normal Form.

    Relation in 1NF

    Each attribute must contain only a single value from its pre-defined domain.

    Second Normal Form

    Before we learn about the second normal form, we need to understand the following −

    • Prime attribute − An attribute, which is a part of the candidate-key, is known as a prime attribute.
    • Non-prime attribute − An attribute, which is not a part of the prime-key, is said to be a non-prime attribute.

    If we follow second normal form, then every non-prime attribute should be fully functionally dependent on prime key attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for which Y → A also holds true.

    Relation not in 2NF

    We see here in Student_Project relation that the prime key attributes are Stu_ID and Proj_ID. According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon both and not on any of the prime key attribute individually. But we find that Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID independently. This is called partial dependency, which is not allowed in Second Normal Form.

    Relation  in 2NF

    We broke the relation in two as depicted in the above picture. So there exists no partial dependency.

    Third Normal Form

    For a relation to be in Third Normal Form, it must be in Second Normal form and the following must satisfy −

    • No non-prime attribute is transitively dependent on prime key attribute.
    • For any non-trivial functional dependency, X → A, then either −
    • A is prime attribute.
    Relation not in 3NF

    We find that in the above Student_detail relation, Stu_ID is the key and only prime key attribute. We find that City can be identified by Stu_ID as well as Zip itself. Neither Zip is a superkey nor is City a prime attribute. Additionally, Stu_ID → Zip → City, so there exists transitive dependency.

    To bring this relation into third normal form, we break the relation into two relations as follows −

    Relation in 3NF

    Boyce-Codd Normal Form

    Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF states that −

    • For any non-trivial functional dependency, X → A, X must be a super-key.

    In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key in the relation ZipCodes. So,

    Stu_ID → Stu_Name, Zip

    and

    Zip → City

    Which confirms that both the relations are in BCNF.

  • Finding Attribute Closure and Candidate Keys using Functional Dependency

    In database management and normalization, it’s important that one understands the concepts of functional dependency, closure property, and candidate keys. These concepts help us design efficient relational schemas, ensure data integrity, and optimize queries. In this chapter, we will elaborate these concepts with the help of practical examples and also understand the process of finding closures and identifying candidate keys.

    What is Functional Dependency?

    For a basic recap on functional dependency, it describes a relationship between attributes in a relational schema. If X → Y, it means the value of X uniquely determines the value of Y. Now here, X is the determinant, and Y is the dependent.

    Let us see one example for this. In a table where each employee has a unique ID, the dependency ID → Name this signifies that knowing an employee’s ID is enough to find their name.

    Functional dependencies can be defined formally. Consider two tuples, T1 and T2, in a relational schema. If T1.X = T2.X this implies T1.Y = T2.Y. Then X → Y is a valid functional dependency.

    But this relationship is not necessarily reciprocal. So the attribute Y may not determine X.

    Example of Functional Dependency

    Let us consider a relational schema R (A, B, C) with the following data −

    ABC
    114
    113
    426
    657

    Let’s understand the dependencies −

    • A → C − This does not hold. This is because A = 1 maps to both C = 4 and C = 3.
    • A → B − This is valid since each unique value of A maps to a unique value of B.
    • B → A − This is also valid for the given dataset.

    Thus, we derive the following functional dependencies −

    • A → B
    • B → A

    What is Attribute Closure?

    The closure of an attribute set, X, which is denoted as X+. This is the set of all attributes that can be determined by X using the given functional dependencies. The closures properties help us to identify keys and candidate keys for a relational schema.

    Following are the Steps to Find Closure −

    • We can start with X+ = X (the attribute set itself).
    • Iteratively add attributes that can be determined from the functional dependencies.
    • Stop when no more attributes can be added to X+.

    Example of Closure

    Using the functional dependencies, say, A → B, B → D, and CD → E −

    Finding A+Finding B+
    Start with A+ = {A}A → B: Add B to A+B → D: Add D to A+CD → E: A+ contains C and D, so add EStart with B+ = {B}B → D: Add D toB+No further dependencies to apply
    Final closure: A+={A,B,C,D,E}Final closure: B+={B,D}

    Concept of Candidate Key

    A candidate key is a minimal set of attributes that can uniquely identify all other attributes in a relational schema.

    • A candidate key’s closure must contain all attributes in the schema.
    • If multiple candidate keys exist, they provide alternate ways to uniquely identify tuples.

    Finding Candidate Keys

    To find candidate keys we must follow the following set of points in mind.

    • Compute the closure of each attribute (or combination of attributes).
    • If the closure contains all attributes in the schema then the attribute set is a candidate key.
    • Ensure the minimality by checking if removing any attribute from the set still results in a closure containing all attributes.

    Example of Candidate Keys

    Relational Schema R (A, B, C, D, E) −

    Functional dependencies −

    • A → B, C
    • B → D
    • CD → E

    Step 1: Find Closures

    The following table highlights how you can find closures −

    Finding A+B+CD+
    Start with {A}A → B, C: Add B, CB → D: Add DCD → E: Add EA+={A,B,C,D,E}Start with {B}B → D: Add DNo further dependencies to applyB+={B,D}Start with {C, D}CD → E: Add EC, D, E does not reach A or B, so CD+ is incomplete
    A+ contains all attributes, so A is a candidate key.B+ does not contain all attributes, so B is not a candidate key.CD is not a candidate key.

    Step 2: Check Combinations

    Other candidate keys can be found by combining attributes and checking closures.

    Shortcut for Finding Candidate Keys −

    • If a single attribute or minimal set of attributes has a closure, and it is containing all schema attributes, that set is a candidate key. Additionally:
    • If E is determined by CD, then CD can be replaced with CB. This combinations involving B should be checked.

    By systematically using dependencies, we can infer keys without exhaustive searches.

    Conclusion

    In this chapter, we understood how to use functional dependencies to find closures and candidate keys. We started with the basics of functional dependency and understood its role in identifying relationships between attributes. Then, we used examples to understand how closures work and how they help determine candidate keys.

    We also analyzed the efficient methods for finding candidate keys and highlighted their significance in relational schema design.

  • Equivalence of Functional Dependencies

    Functional dependencies are quite useful while making databases and designing proper table relations. Functional dependencies define relationships between attributes in a table; they help in normalizing the tables and ensuring data consistency as well.

    A common question in this domain is how to compare two sets of functional dependencies and determine if they are equivalent. Read this chapter to get a good understanding of the concept of equivalence of functional dependencies and explain how to determine if one set is a subset of another, or if both sets are the same.

    What is Equivalence of Functional Dependencies?

    Consider there are two sets of functional dependencies, F and G. They are considered equivalent if −

    • Every dependency in F can be derived from G.
    • Every dependency in G can be derived from F.

    In other words, F ⊆ G and G ⊆ F. If both conditions hold, then F and G are equal.

    The Importance of Equivalence

    It is important to have a good understanding of the concept of “equivalence” while designing databases or while performing normalization and query optimization. It ensures that dependencies are not repeated and helps to compare alternative dependency sets to see if they represent the same relationship.

    How to Compare Two Sets of Functional Dependencies?

    To check whether two Functional Dependencies are equivalent, we can use the “closure of attributes”. The closure of an attribute set is the set of attributes that can be determined using the given functional dependencies.

    The process involves −

    • Calculating closures for attributes using one set of dependencies.
    • Verifying if these closures match when computed using the other set.
    • Repeating the process with the roles reversed to ensure equivalence.

    Step-by-Step Example

    Let us see one example for a relational schema R with attributes and two sets of functional dependencies F and G −

    Set FSet G
    A → CAC → DE → AHA → CDE → AH

    We will check if F and G are equivalent or not.

    Step 1: Compute Closures Using G

    We start by computing the closure of each attribute or attribute combination from F. Here we calculate them using the functional dependencies in G.

    Closure of A Using G −

    • A is in the closure by itself
    • A → CD (from G): Add C and D to the closure
    • Closure of A is: {A, C, D}

    Closure of AC Using G −

    • Start with AC
    • A → CD (from G): Add C and D to the closure
    • Closure of AC: {A, C, D}

    Closure of E Using G −

    • E is in the closure by itself
    • E → AH (from G): Add A and H
    • A → CD (from G): Add C and D using A

    Closure of E: {E, A, H, C, D}

    At this point, we have computed closures for A, AC, and E using G.

    Step 2: Verify F ⊆ G

    Now, we check if F’s dependencies are covered by G −

    Dependency A → C from F −

    • Closure of A using G: {A, C, D}
    • C is in the closure, so A → C is valid in G

    Dependency AC → D from F −

    • Closure of AC using G: {A, C, D}
    • D is in the closure, so AC → D is valid in G

    Dependency E → A, H from F −

    • Closure of E using G: {E, A, H, C, D}
    • A and H are in the closure, so E → A, H is valid in G

    Since all dependencies in F can be derived from G, F ⊆ G is true.

    Step 3: Compute Closures Using F

    Next, we compute closures for attributes in G, but this time using F.

    Closure of A Using F −

    • A is in the closure by itself
    • A → C (from F): Add C to the closure
    • AC → D (from F): Add D using AC
    • Closure of A: {A, C, D}

    Closure of E Using F −

    • E is in the closure by itself
    • E → A, H (from F): Add A and H
    • A → C (from F): Add C
    • AC → D (from F): Add D using AC

    Closure of E: {E, A, H, C, D}

    Step 4: Verify G ⊆ F

    Finally, we check if G’s dependencies are covered by F −

    Dependency A → CD from G −

    • Closure of A using F: {A, C, D}
    • C and D are in the closure, so A → CD is valid in F

    Dependency E → AH from G −

    • Closure of E using F: {E, A, H, C, D}
    • A and H are in the closure, so E → AH is valid in F

    Since all dependencies in G can be derived from FG ⊆ F is true.

    Conclusion: F and G Are Equivalent

    From the above steps, we conclude that F ⊆ G and G ⊆ F. It means F and G are equivalent functional dependency sets.

    Key Points to Note

    Take a note of the following key points –

    • Use Closures for Comparison − To compare two sets of dependencies, we must compute closures for each attribute or attribute set.
    • Check Both Directions − Verify the subsets like F ⊆ G and G ⊆ F to ensure equivalence.
    • Simplify Where Possible − Minimize the dependency sets before comparison to avoid unnecessary computations.

    Conclusion

    In this chapter, we understood how to determine the equivalence of functional dependencies. We started the discussion by understanding the concept and importance of equivalence, followed by a step-by-step process to compare two sets of dependencies.

    Using closures, we verified that both sets could derive the same attributes, proving their equivalence. This process is needed in database design; it helps in identifying redundant dependencies and in performing schema normalization.

  • Minimal Cover

    In database management systems (DBMS), a minimal cover (or irreducible set) is a simplified version of a given set of functional dependencies. It preserves the original meaning but eliminates redundancies and unnecessary complexities. One needs to learn the process of finding a minimal cover for database normalization. It helps in creating efficient and well-structured tables.

    In this chapter, we will explain the concept of minimal cover in simple steps, and see the process with an example for a better understanding.

    What is Minimal Cover in Functional Dependency?

    A minimal cover of a set of functional dependencies is an equivalent set that satisfies these conditions −

    • The right-hand side (RHS) of every functional dependency has exactly one attribute.
    • No functional dependency will be redundant.
    • The left-hand side (LHS) of every functional dependency is as small as possible. It means we cannot remove any attribute without losing the dependency.

    With these conditions, a minimal cover helps us in simplifying the design while retaining the same functional relationships as the original set.

    Steps to Find Minimal Cover

    Let us now understand how to find the minimal cover. To compute the minimal cover, we follow three key steps −

    • Decompose the RHS − It shows that every functional dependency has only one attribute on its RHS.
    • Remove Redundant Functional Dependencies − Check and eliminate any dependencies that are not needed.
    • Minimize the LHS − Simplify the LHS of each dependency by removing unnecessary attributes.

    Let us get a good understanding of these steps see these steps down further with an example.

    Example: Finding the Minimal Cover

    Suppose we are given the following functional dependencies −

    • A → B
    • C → B
    • D → A, B, C
    • AC → D

    We aim to find the minimal cover for this set.

    Step 1: Decompose the RHS

    First, we make sure that each functional dependency has only one attribute on its RHS. This is done using the decomposition property.

    • A → B: This is already in the correct form. It has the RHS has a single attribute.
    • C → B: Again, this is fine as is.
    • D → A, B, C: Here, the RHS has three attributes. We decompose it into three separate dependencies:
      • D → A
      • D → B
      • D → C
    • AC → D: The RHS has one attribute. So it remains unchanged.

    After Step 1, our updated set of dependencies looks like this −

    • A → B
    • C → B
    • D → A
    • D → B
    • D → C
    • AC → D

    Step 2: Remove Redundant Dependencies

    Next, we check each functional dependency. To see if it is redundant. A dependency is redundant if it can be removed without changing the meaning of the set. This shows finding closures and verifying if the dependent attribute can still be determined without the removed dependency.

    • Check A → B − Remove A → B and calculate the closure of A using the remaining dependencies. The closure of A only includes A. Since B is not in the closure, A → B is not redundant and must be kept.
    • Check C → B − Remove C → B and calculate the closure of C. The closure of C only includes C. So B cannot be determined. Thus, C → B is not redundant and must be kept.
    • Check D → A − Remove D → A and calculate the closure of D. The closure of D includes D, B, C, but A cannot be determined without this dependency. Therefore, D → A is not redundant and must stay.
    • Check D  B − Remove D → B and calculate the closure of D. The closure of D still includes B. So D → B is redundant and can be removed.
    • Check D → C − Remove D → C and calculate the closure of D. The closure of D does not include C, so D → C is not redundant and must stay.
    • Check AC → D − Remove AC → D and calculate the closure of AC. Without AC → D, D cannot be determined. So this dependency is not redundant and must stay.

    After Step 2, the updated set of dependencies is −

    • A → B
    • C → B
    • D → A
    • D → C
    • AC → D

    Step 3: Minimize the LHS

    In the final step, we minimize the LHS of each dependency. It involves removing attributes from the LHS if they are not needed to determine the RHS.

    Minimize AC → D −

    Check if either A or C can be removed from the LHS.

    • Remove A and calculate the closure of C. The closure of C does not include D, so A cannot be removed.
    • Remove C and calculate the closure of A. The closure of A also does not include D, so C cannot be removed.

    Thus, AC → D remains as is.

    All other dependencies already have a single attribute on the LHS. So, no further minimization is needed.

    Final Minimal Cover

    The minimal cover for the given functional dependencies is −

    • A → B
    • C → B
    • D → A
    • D → C
    • AC → D

    Importance of Minimal Cover

    Minimal cover is needed because it simplifies the set of functional dependencies while maintaining their original meaning. It helps in −

    • Avoiding redundant computations.
    • Reducing the complexity of database design.
    • Making normalization easier.

    By ensuring that both the LHS and RHS of dependencies are as simple as possible, the minimal cover aids in creating efficient and well-organized databases.

  • Functional Dependency

    Functional Dependency is one of the basic but important concepts in databases. It is highly useful in understanding normalization and how attributes in a table relate to one another. We have come across this term “functional dependency” while studying the concepts of Database Design and topics like Keys and Normal Forms.

    In this chapter, we will cover the concepts of functional dependencies in detail with simple explanations and practical examples for a better understanding.

    What is Functional Dependency?

    In short, functional dependency is all about relationships between attributes (columns) in a table. We can say that the value of one attribute (or a group of attributes) can be used to determine the value of another attribute in the same table.

    Think of it this way: If we know the value of A, can we always find the corresponding value of B? If yes, then we say A determines B, or we can represent this with an arrow, A → B. We can also say that B is dependent on A.

    To get a better understanding, let us compare this concept with a function in mathematics. Imagine we have a function f where we input a number ‘a‘, and it calculates the square of that number as the output ‘b‘.

    For example − Input a = 5, the function calculates b = 25. Here, “a uniquely determines b“.

    In databases, it is a little bit different. Instead of calculating a value, we simply use one attribute (or a set of attributes) to find or identify another. Let us see this with a table example.

    Functional Dependency in Action

    Consider a table T with two columns, A and B −

    AB
    1X
    2Y
    3Z

    Here, if someone gives us the value of A, like A = 2, we can look at the table and find that the corresponding value of B is Y. This tells us that A determines B, or A → B.

    Key Components of Functional Dependency

    In functional dependencies we must keep in mind several terms or components −

    • Determinant − The attribute(s) used to determine the other attribute (Left hand attribute)
    • Dependent − The attribute whose value is determined (Right hand attribute)

    In the example above −

    • A is the determinant
    • B is the dependent

    Examples of Functional Dependency

    Let us see more detailed examples and analyze if the dependencies are valid or not.

    Example 1: Roll Number Determines Student Information

    Imagine a table with the following attributes: (Roll Number, Student Name, Department Name, and Department Building).

    Roll NumberStudent NameDepartment NameDepartment Building
    1AliceCSA4
    2BobITB2
    3CarolCSA4

    If we say Roll Number → Student Name, Department Name, Department Building, is this a valid functional dependency?

    Yes, because, each roll number is unique, meaning it can help us identify the student’s name, department, and building. For example −

    If Roll Number = 3, we can easily find that the student is Carol, in the CS department, and her building is A4.

    Example 2: Department Name Determines Department Building

    Using the same table, let us see another example. Check if Department Name → Department Building is a valid functional dependency or not. Observe carefully, the Department Name column has duplicate values: “CS” appears twice. However, for both instances, the corresponding Department Building is the same (A4).

    So, even though there’s redundancy, this is still a valid dependency because CS always maps to A4, no matter how many times it appears.

    Example 3: Different Determinants with the Same Dependent

    Now, consider another functional dependency, say Department Name → Department Building, but we add another department to the table −

    Department NameDepartment Building
    CSA4
    ITB2
    MEB2

    Here, two departments (IT and ME) share the same building (B2). Is this valid?

    Yes, it is also valid. Multiple determinants (IT and ME) can point to the same dependent (B2). This does not violate the rules of functional dependency.

    Example 4: Student Name Determines Department Name

    Consider another example. Here the functional dependency Student Name → Department Name.

    In our table, two students (Bob and another student) could share the same name but belong to different departments. For instance −

    Student NameDepartment Name
    BobCS
    BobIT

    If we ask, “Which department is Bob in?”, there are two possible answers: CS and IT. This makes the dependency invalid. This is because a single determinant (Student Name) does not lead to a unique dependent (Department Name).

    Analyzing Valid and Invalid Cases

    Now let us categorize functional dependency scenarios −

    • Unique Determinant to Unique Dependent − Example: Roll Number → Student Information. This is valid because each roll number is unique and maps to a specific set of values.
    • Same Determinant with Same Dependent − Example: Department Name → Department Building. Valid even with duplicate department names. And as they always map to the same building.
    • Different Determinants with Same Dependent − Example: IT → B2, ME → B2. This is valid because multiple attributes can lead to the same dependent value.
    • Same Determinant with Different Dependents − Example: Student Name → Department Name (with duplicates). This is invalid because one determinant (Student Name) leads to multiple, conflicting values.

    Importance of Functional Dependency

    The functional dependencies are important for database normalization. They help us identify several factors as listed below −

    • Redundancies in data
    • Which attributes should serve as keys
    • How to design efficient, error-free database structures

    Without properly handling functional dependencies, we might design database tables that are prone to anomalies and inefficiencies.

  • Example of Queries on Relational Algebra

    Relational Algebra provides the theoretical foundation of querying. It is used for understanding and manipulating data in relational databases. It is used for a variety of operations to query and transform datasets effectively. By understanding these operations, database users can perform complex queries while maintaining clarity and precision.

    In this chapter, we will see several query examples from relational algebra. Each example is based on a specific scenario and demonstrates the practical application of relational algebra operations such as selection, projection, join, union, and division.

    Let us first take a look at the required tables and their data to express the query in true sense.

    EMPLOYEE Table

    Here’s the EMPLOYEE table that collects the data relevant to all employees –

    FnameMinitLnameSsnBdateAddressSexSalarySuper_ssnDno
    JohnBSmith1234567891965-01-09731 Fondren, Houston, TXM300003334455555
    FranklinTWong3334455551955-12-08638 Voss, Houston, TXM400008886655555
    AliciaJZelaya9998877771968-01-193321 Castle, Spring, TXF250009876543214
    JenniferSWallace9876543211941-06-20291 Berry, Bellaire, TXF430008886655554
    RameshKNarayan6668844441962-09-15975 Fire Oak, Humble, TXM380003334455555
    JoyceAEnglish4534534531972-07-315631 Rice, Houston, TXF250003334455555
    AhmadVJabbar9879879871969-03-29980 Dallas, Houston, TXM250009876543214
    JamesEBorg8886655551937-11-10450 Stone, Houston, TXM55000NULL1

    DEPARTMENT Table

    There are three departments as highlighted in the following DEPARTMENT table –

    DnameDnumberMgr_ssnMgr_start_date
    Research53334455551988-05-22
    Administration49876543211995-01-01
    Headquarters18886655551981-06-19

    PROJECT Table

    The PROJECT table contains the relevant data of all the projects –

    PnamePnumberPlocationDnum
    ProductX1Bellaire5
    ProductY2Sugarland5
    ProductZ3Houston5
    Computerization10Stafford4
    Reorganization20Houston1
    Newbenefits30Stafford4

    WORKS_ON Table

    The WORKS_ON table gathers which employee is working on which project for how many hours –

    EssnPnoHours
    123456789132.5
    12345678927.5
    666884444340.0
    453453453120.0
    453453453220.0
    333445555210.0
    333445555310.0
    3334455551010.0
    3334455552010.0
    9998877773030.0
    9998877771010.0
    9879879871035.0
    987987987305.0
    9876543213020.0
    9876543212015.0
    88866555520NULL

    DEPENDENT Table

    The DEPENDENT table is as follows –

    EssnDependent_nameSexBdateRelationship
    333445555AliceF1986-04-05Daughter
    333445555TheodoreM1983-10-25Son
    333445555JoyF1958-05-03Spouse
    987654321AbnerM1942-02-28Spouse
    123456789MichaelM1988-01-04Son
    123456789AliceF1988-12-30Daughter
    123456789ElizabethF1967-05-05Spouse

    Query Examples on Relational Algebra

    Let us now check some queries that extracts data from the inputs supplied in the above tables –

    Retrieve the Name and Address of Employees in the Research Department

    This query is to identify employees working in the “Research” department and retrieve their names and addresses.

    Steps − Use a selection operation to filter the “Research” department from the DEPARTMENT relation –

    RESEARCHDEPT←σDname=′Research′(DEPARTMENT)

    DnameDnumberMgr_ssnMgr_start_date
    Research53334455551988-05-22

    Join the resulting relation with the EMPLOYEE relation using the department number (Dnumber and Dno) –

    RESEARCHEMPS←RESEARCHDEPT⋈Dnumber=DnoEMPLOYEE

    DnameDnumberMgr_ssnMgr_start_dateFnameMinitLnameSsnBdateAddressSexSalarySuper_ssnDno
    Research53334455551988-05-22JohnBSmith1234567891965-01-09731 Fondren, Houston, TXM300003334455555
    Research53334455551988-05-22FranklinTWong3334455551955-12-08638 Voss, Houston, TXM400008886655555
    Research53334455551988-05-22RameshKNarayan6668844441962-09-15975 Fire Oak, Humble, TXM380003334455555
    Research53334455551988-05-22JoyceAEnglish4534534531972-07-315631 Rice, Houston, TXF250003334455555

    Finally, apply a projection operation to retrieve the desired attributes (first name, last name, and address).

    RESULT←πFname,Lname,Address(RESEARCHEMPS)

    FnameLnameAddress
    JohnSmith731 Fondren, Houston, TX
    FranklinWong638 Voss, Houston, TX
    RameshNarayan975 Fire Oak, Humble, TX
    JoyceEnglish5631 Rice, Houston, TX

    In-Line Expression −

    πFname,Lname,Address(σDname=′Research′(DEPARTMENT⋈Dnumber=DnoEMPLOYEE))

    List Project Details for Stafford

    For projects located in “Stafford,” we are going to retrieve the project number, the controlling department, and the manager’s details (last name, address, and birth date).

    Steps − Filter projects located in “Stafford” using selection.

    STAFFORD_PROJS←σPlocation=′Stafford′(PROJECT)

    PnamePnumberPlocationDnum
    Computerization10Stafford4
    Newbenefits30Stafford4

    Join these projects with their controlling departments based on the department number –

    CONTR_DEPTS←STAFFORD_PROJS⋈Dnum=DnumberDEPARTMENT

    PnamePnumberPlocationDnumDnameDnumberMgr_ssnMgr_start_date
    Computerization10Stafford4Administration49876543211995-01-01
    Newbenefits30Stafford4Administration49876543211995-01-01

    Join the result with the EMPLOYEE relation to retrieve manager details (Mgr_ssn = Ssn) –

    PROJ_DEPT_MGRS←CONTR_DEPTS⋈Mgr_ssn=SsnEMPLOYEE

    PnamePnumberPlocationDnumDnameDnumberMgr_ssnMgr_start_dateFnameMinitLnameSsn
    Computerization10Stafford4Administration49876543211995-01-01JenniferSWallace987654321
    Newbenefits30Stafford4Administration49876543211995-01-01JenniferSWallace987654321

    Finally, use projection to extract the desired attributes.

    RESULT←πPnumber,Dnum,Lname,Address,Bdate(PROJ_DEPT_MGRS)

    PnumberDnumLnameAddressBdate
    104Wallace291 Berry, Bellaire, TX1941-06-20
    304Wallace291 Berry, Bellaire, TX1941-06-20

    Employees Working on All Projects Controlled by Department 5

    This query identifies employees assigned to every project under department number 5.

    Steps − Create a relation with project numbers of all projects controlled by department 5 –

    DEPT5_PROJS←ρ(Pno)(πPnumber(σDnum=5(PROJECT)))

    Pno
    1
    2
    3

    Build a relation of employees and their assigned projects (Ssn and Pno).

    EMP_PROJ←ρ(Ssn,Pno)(πEssn,Pno(WORKS_ON))

    SsnPno
    1234567891
    1234567892
    6668844443
    4534534531
    4534534532
    3334455552
    3334455553
    33344555510
    33344555520
    99988777730
    99988777710
    98798798710
    98798798730
    98765432130
    98765432120
    88866555520

    Apply the division operation to find employees associated with all DEPT5_PROJS.

    RESULT_EMP_SSNS←EMP_PROJ÷DEPT5_PROJS

    Join with the EMPLOYEE relation to retrieve names.

    RESULT←πLname,Fname(RESULT_EMP_SSNS∗EMPLOYEE)

    Project Numbers Involving Smith (As Worker or Manager)

    We want to identify all projects where an employee named “Smith” is involved. This is either as a worker or as a department manager.

    Steps − Retrieve the Social Security Numbers (SSNs) of employees named “Smith” –

    SMITHS(Essn)←πSsn(σLname=′Smith′(EMPLOYEE))

    Essn
    123456789

    Use the Cartesian product to find projects where “Smith” works.

    SMITH_WORKER_PROJS←πPno(WORKS_ON∗SMITHS)

    EssnPnoHours
    123456789132.5
    12345678927.5

    Retrieve SSNs of department managers from the DEPARTMENT relation –

    MGRS←πLname,Dnumber(EMPLOYEE⋈Ssn=Mgr_ssnDEPARTMENT)

    LnameDno
    Wong5
    Wallace4
    Borg1

    Find the departments managed by “Smith” and join them with PROJECT to identify projects –

    SMITH_MANAGED_DEPTS(Dnum)←πDnumber(σLname=′Smith′(MGRS))

    SMITH_MGR_PROJS(Pno)←πPnumber(SMITH_MANAGED_DEPTS∗PROJECT)

    Combine the two project lists using union –

    RESULT←(SMITH_WORKER_PROJS∪SMITH_MGR_PROJS)

    Employees with Two or More Dependents

    The goal is to list employees who have at least two dependents. This requires using aggregate functions, which go beyond basic relational algebra.

    Steps − Count the number of dependents for each employee using COUNT –

    T1(Ssn,No_of_dependents)←EssnℑCOUNTDependent_name(DEPENDENT)

    Filter employees with more than two dependents –

    T2←σNo_of_dependents>2(T1)

    Join with EMPLOYEE to get their names –

    RESULT←πLname,Fname(T2∗EMPLOYEE)

    Employees without Dependents

    This query retrieves employees who have no dependents.

    Steps − Create a relation with all employee SSNs.

    ALL_EMPS←πSsn(EMPLOYEE)

    Create a relation of employees with dependents.

    EMPS_WITH_DEPS(Ssn)←πEssn(DEPENDENT)

    Use the set difference to find employees with no dependents.

    EMPS_WITHOUT_DEPS←(ALLEMPS–EMPS_WITH_DEPS)

    Join with EMPLOYEE to retrieve names.

    RESULT←πLname,Fname(EMPS_WITHOUT_DEPS∗EMPLOYEE)

    Managers with Dependents

    This query lists managers who have at least one dependent.

    Steps − Extract SSNs of department managers –

    MGRS(Ssn)←πMgrssn(DEPARTMENT)

    Extract SSNs of employees with dependents –

    EMPS_WITH_DEPS(Ssn)←πEssn(DEPENDENT)

    Use intersection to find managers with dependents –

    MGRS_WITH_DEPS←(MGRS∩EMPS_WITH_DEPS)

    Retrieve their names –

    RESULT←πLname,Fname(MGRS_WITH_DEPS∗EMPLOYEE)