Unit II Database Design 1
Unit II Database Design 1
Sample:
ER-to-Relational Mapping:
First Convert each entity and relationship to tables. Person table corresponds to Person Entity with key
as Per-Id. Similarly Passport table corresponds to Passport Entity with key as Pass-No. Has Table
represents relationship between Person and Passport (Which person has which passport). So it will take
attribute Per-Id from Person and Pass-No from Passport.
PR3 –
Binary Relationship with 1:1 cardinality and partial participation of both entities :
First Convert each entity and relationship to tables. Male table corresponds to Male Entity with key as
M-Id. Similarly Female table corresponds to Female Entity with key as F-Id. Marry Table represents
relationship between Male and Female (Which Male marries which female). So it will take attribute M-Id
from Male and F-Id from Female.
Male Marry Female
M1 – M1 F2 F1 –
M2 – M2 F1 F2 –
M3 – F3 –
First Convert each entity and relationship to tables. Student table corresponds to Student Entity with
key as S-Id. Similarly Elective_Course table corresponds to Elective_Course Entity with key as E-Id.
Enrolls Table represents relationship between Student and Elective_Course (Which student enrolls in
which course). So it will take attribute S-Id from Student and E-Id from Elective_Course.
Student Enrolls Elective_Course
S1 – S1 E1 E1 –
S2 – S2 E2 E2 –
S3 – S3 E1 E3 –
S4 – S4 E1
First Convert each entity and relationship to tables. Student table corresponds to Student Entity with
key as S-Id. Similarly Compulsory_Courses table corresponds to Compulsory Courses Entity with key as
C-Id. Enrolls Table represents relationship between Student and Compulsory_Courses (Which student
enrolls in which course). So it will take attribute S-Id from Person and C-Id from Compulsory_Courses.
Student Enrolls Compulsory_Courses
S1 – S1 C1 C1 –
S2 – S1 C2 C2 –
S3 – S3 C1 C3 –
S4 – S4 C3 C4 –
S4 C2
S3 C3
First Convert each entity and relationship to tables. Employee table corresponds to Employee Entity
with key as E-Id. Similarly Dependents table corresponds to Dependent Entity with key as D-Name and
E-Id. Has Table represents relationship between Employee and Dependents (Which employee has
which dependents). So it will take attribute E-Id from Employee and D-Name from Dependents.
E1 – E1 RAM RAM E1 –
E2 – E1 SRINI SRINI E1 –
E3 – E2 RAM RAM E2 –
E3 ASHISH ASHISH E3 –
They describe the relationships between attributes in a relation (table) and help
ensure data integrity and normalization. It essentially means that the value of one
set of attributes determines the value of another set. For example, if we have
attributes A and B in a relation, we say that B is functionally dependent on A if, for
every value of A, there is only one corresponding value of B.
If X and Y are sets of attributes in a relation R, we say that Y is functionally
dependent on X (denoted as X -> Y) if, for every possible instance of X in R, there is
only one instance of Y.
Example:
Types:
Trivial Functional Dependencies: These are dependencies where the dependent attribute(s) are a
subset of the determinant attribute(s). For example, if X -> Y holds, then Y is a subset of X.
Non-Trivial Functional Dependencies: These are dependencies where the dependent attribute(s) are
not a subset of the determinant attribute(s). They convey significant relationships between attributes in
the database.
Partial Functional Dependencies: These are dependencies where an attribute is functionally dependent
on only a part of a composite key (multiple attributes acting as the primary key).
Multivalued Dependencies (MVDs): These describe relationships among attributes where the presence
of certain values in one attribute determines the presence of other values in another attribute. They are
more complex than simple functional dependencies and are essential for database normalization
beyond third normal form (3NF).
Decomposition
Decomposition in the context of database management refers to the process of breaking down a single
relation (table) into multiple smaller relations. This process is typically carried out during database
normalization to reduce redundancy, improve data integrity, and facilitate efficient data management.
Types :
Lossy decomposition:
Lossy decomposition, also known as lossy join decomposition, refers to a decomposition process in
database normalization where some information is lost during the decomposition, and as a result, it
cannot be reconstructed exactly from the decomposed relations. Unlike lossless decomposition, where
the original relation can be fully reconstructed, lossy decomposition results in the loss of some data or
information.
Name
Department
Salary
Now, let's say we want to decompose this relation into smaller relations while ensuring non-loss
decomposition.
Step 2: Choose a Normal Form: Let's aim for Third Normal Form (3NF) for this example.
Step 3: Perform Decomposition: Based on the identified functional dependencies, we can decompose
the Employee relation into two smaller relations:
Relation 1 (Employee_Details):
Name
Department
Salary
Relation 2 (Management):
Step 4: Verify Losslessness: To ensure non-loss decomposition, we need to verify that we can
reconstruct the original Employee relation by joining the decomposed relations together. We can
achieve this by performing a natural join on the common attribute (EmployeeID) between the two
relations.
This query should return the original Employee relation without any loss of information.
Step 5: Enforce Referential Integrity: Ensure that referential integrity is maintained between the
decomposed relations by defining appropriate foreign key constraints and ensuring that each foreign
key references a valid primary key.
First Normal Form (1NF) is the initial step in the normalization process of a
relational database schema.
Atomic Values: Each attribute (column) in a relation must contain atomic (indivisible)
values. This means that the values cannot be further divided into smaller pieces. If
an attribute contains multiple values or composite values, it violates 1NF. To
conform to 1NF, attributes should be atomic.
Unique Column Names: Each column in a relation must have a unique name. This
ensures that attributes are distinctly identifiable within the relation.
Courses Table:
CourseID Course
1 Math
2 Science
3 English
4 History
5 Spanish
Next, let's modify the original table to reference the courses from the new
table:
StudentID Name
1 Alice
2 Bob
3 Charlie
StudentCourses Table:
StudentID CourseID
1 1
1 2
1 3
2 4
2 1
3 2
3 5
In this normalized structure, each table represents a single entity, and each
attribute
+------------+----------+-------------+
| Project_ID | Project | Department |
+------------+----------+-------------+
| 101 | Project1 | HR |
| 102 | Project2 | HR |
| 103 | Project3 | Finance |
+------------+----------+-------------+
Multi-valued dependencies
Multi-valued dependencies (MVDs) are a type of constraint in relational database
theory that describe certain relationships between attributes within a table. They
extend the concept of functional dependencies and are used to ensure the integrity
of data in a normalized database schema.
if student ID 1 is enrolled in courses with IDs 101 and 102, and for each
course, there's a set of textbook ISBNs associated uniquely, then we have a
multi-valued dependency:
Here, knowing the value of B (Course ID) determines the set of values for C
(Textbook ISBNs) for each student (A). This dependency holds regardless of
which courses the student is enrolled in.
Third Normal Form (3NF) in database design is important for further improving
data integrity and reducing redundancy beyond First Normal Form (1NF) and
Second Normal Form (2NF).
Condition:
+-----------+------------+----------+-------------+
+-----------+------------+----------+-------------+
EmployeeProject Table:
+-----------+------------+
| Employee | Project_ID |
+-----------+------------+
| John | 101 |
| John | 102 |
| Alice | 101 |
| Alice | 103 |
+-----------+------------+
Project Table:
+------------+----------+
| Project_ID | Project |
+------------+----------+
| 101 | Project1 |
| 102 | Project2 |
| 103 | Project3 |
+------------+----------+
Department Table:
+------------+-------------+
| Project_ID | Department |
+------------+-------------+
| 101 | HR |
| 102 | HR |
| 101 | Finance |
| 103 | Finance |
+------------+-------------+
---------------------------------------------------
Relation 1 (EmployeeProject):
Employee_ID | Project_ID
-------------------------
E001 | P101
E001 | P102
E002 | P101
E002 | P103
--------------------------------------
P101 | Project1 | HR
P102 | Project2 | HR
In this table:
1. Employees Table:
Employee ID Employee Name
1 Alice
2 Bob
3 Charlie
2. Projects Table:
Project ID Project Name
101 Project X
102 Project Y
103 Project Z
3. Employee_Projects Table (to represent the many-to-many relationship
between employees and projects):
Employee ID Project ID
1 101
1 102
2 101
3 102
3 103
Now, the original table has been decomposed into three tables, each
representing a single entity without any multi-valued dependencies. This
satisfies Fourth Normal Form (4NF) by removing the indirect dependency
between Employee Name and Project Name through the composite keys
Employee ID and Project ID.
5nf:
Fifth Normal Form (5NF), also known as Project-Join Normal Form (PJNF), is a level of
database normalization that deals with complex relationships between attributes in
a table. While it's less commonly discussed than lower normal forms like 3NF and
4NF, it addresses certain types of join dependencies that may exist in a database
schema.
To explain Fifth Normal Form (5NF), let's start with a table that contains
information about employees and the departments they work in:
In this table:
In 5NF, we are concerned with join dependencies where the join operation
itself causes a redundancy or anomaly. In this table, we have a join
dependency between Department Name and Manager ID. For example, in
the HR department, both Alice and Charlie report to the manager with
Employee ID 10.
1. Employees Table:
Employee ID Employee Name Department ID Manager ID
1 Alice 101 10
2 Bob 102 11
3 Charlie 101 10
4 Diana 103 12
5 Eric 102 11
2. Departments Table:
Department ID Department Name
101 HR
102 IT
103 Finance
3. Management Table:
Department ID Manager ID
101 10
102 11
103 12
Now, the original table has been decomposed into three tables, and the join
dependency between Department Name and Manager ID has been
eliminated. Each table represents a single entity without any join
dependencies causing redundancy or anomalies, satisfying Fifth Normal
Form (5NF).
Possible 2 mark