DBMS Assignment 2
DBMS Assignment 2
Question 2:
What is BCNF? Provide the condition that a relation
must satisfy to be in a BCNF?
Question 3:
Discuss the concept of JDs. How does it relate to
Fourth Normal Form and Fifth Normal Form?
How JDs Relate to Fifth Normal Form (5NF)
What is Fifth Normal Form (5NF)?
A table is in 5NF (or Projection-Join Normal Form, PJNF) if:
1. It is in 4NF.
2. It has no non-trivial join dependencies.
Key Concept of 5NF
• While 4NF deals with decompositions involving two sub-relations (MVDs), 5NF
ensures correctness for decompositions into three or more sub-relations (complex
JDs).
Relation Between JD and 5NF
• A table violates 5NF if it can be decomposed into three or more sub-relations without
loss of information, but the table is not already in that decomposed form.
• 5NF ensures that the decomposition guided by JDs is complete and no unnecessary
redundancy remains.
Observation
• A course belongs to a department.
• An instructor teaches multiple courses.
• The course-instructor relationship is independent of the department.
Problem:
This table has redundancy because:
1. Department names are repeated for each course.
2. Multiple rows combine course-instructor pairs unnecessarily.
Key Takeaway
• 5NF ensures no redundancy caused by complex join dependencies.
• Tables are decomposed into the smallest logical sub-tables that still allow the data to
be reconstructed.
Summary
• Join Dependency (JD) ensures that a table can be split into smaller tables without
losing data.
• 4NF deals with simpler JDs (multivalued dependencies involving two sub-relations).
• 5NF extends this concept to more complex cases involving three or more sub-
relations.
Understanding JDs helps in designing databases that are efficient, free of redundancy, and
maintain data integrity!
Question 4:
Explain Functional Dependencies.
Functional Dependency
Importance of Functional Dependencies
Functional dependencies help in database normalization, which involves decomposing tables
to reduce redundancy and improve data integrity. They are crucial for defining normal
forms, such as:
1. First Normal Form (1NF): Ensures that the values in each column are atomic.
2. Second Normal Form (2NF): Eliminates partial dependencies.
3. Third Normal Form (3NF): Removes transitive dependencies.
4. Boyce-Codd Normal Form (BCNF): Every determinant must be a candidate key,
ensuring further normalization.
Functional Dependency Analysis in Database Design
During design, functional dependencies guide how tables should be structured. By identifying
dependencies:
1. We can reduce data anomalies (insertion, deletion, and update anomalies).
2. We can enhance data consistency by ensuring that data related by dependency is
properly grouped or normalized.
3. They serve as constraints, ensuring that data remains valid according to business
rules.
Functional dependencies are fundamental in maintaining database integrity and efficiency
in querying and updating data in a relational database.
Question 5:
Differentiate between Union and Intersection with
suitable example.
Question 6:
Difference between Queries and Sub-Queries.
Difference Between Queries and Sub-Queries in Databases
In database management systems, queries and sub-queries are both used to retrieve data, but
they work in different ways and have different purposes. Let’s break them down in simple
terms, then go into the details.
1. Queries (Main Queries)
A query is a request to retrieve data from a database. It is usually a standalone statement that
can fetch, update, or manipulate the data.
Key Points:
• Definition: A query is an SQL statement used to interact with the database to retrieve
or manipulate data.
• Execution: It runs independently and returns results directly.
• Types: Queries can be simple (retrieving data from a single table) or complex
(involving multiple tables and conditions).
2. Sub-Queries
A sub-query is a query that is nested inside another query. It is used to retrieve intermediate
results that can be used by the outer query. Sub-queries are placed within parentheses and
often help in filtering or processing data that cannot be handled by a single query.
Key Points:
• Definition: A sub-query is a query written inside another SQL query, often inside the
WHERE, FROM, or SELECT clause of the main query.
• Execution: The database executes the sub-query first to get its result, which is then
used by the main query.
• Purpose: Sub-queries are useful when the result of one query is needed as input for
another query. They allow more complex filtering or transformations that are difficult
to express in a single query.
• Types: Sub-queries can be:
o Single-row sub-queries: Return a single value.
o Multiple-row sub-queries: Return multiple values (like a list).
o Correlated sub-queries: Use values from the outer query.
o Non-correlated sub-queries: Independent from the outer query.
Advantages and Disadvantages
Advantages of Queries:
• Simplicity: Queries are easy to write and execute when dealing with straightforward data
retrieval.
• Performance: For simple operations, a query can be faster as it doesn’t rely on nested
calculations.
Advantages of Sub-queries:
• Complex Filtering: Sub-queries allow you to perform complex filtering and calculations that
would be difficult to express in a single query.
• Modularity: They break down complex problems into smaller, manageable parts.
Disadvantages of Sub-queries:
• Complexity: Sub-queries can make SQL queries harder to read and maintain, especially if
they are nested deeply.
Summary
• Sub-query: A query inside another query, often used to perform intermediate calculations or
retrieve data that the outer query needs.
• You need to use the result of one query in another query, for filtering, calculating aggregates,
or more complex conditions.