SQL ASSIGNMENT – 2
1. Explain normalization and what we are achieving by using the normalization in
the database?
Normalization is the process to eliminate data redundancy and enhance
data integrity in the table. Normalization also helps to organize the data in the
database. It is a multi-step process that sets the data into tabular form and removes
the duplicated data from the relational tables
Normalization is used to achieve the following in the database:-
1. Minimize data redundancy.
2. Improve data consistency and integrity.
3. Reduce data anomalies.
4. Optimize database performance.
5. Make it easier to maintain and modify the database.
2. Explain normal forms. Difference between normalization and normal forms?
Normalization is the process of organizing data in a database in a
way that reduces redundancy and dependency among the tables.
Normal forms are a set of guidelines that define the level of
normalization that a database table has achieved.
Difference between Normalization and normal forms.
The difference between normalization and normal forms is that
normalization is the process of organizing data in a database, while
normal forms are the guidelines that are used to achieve this organization.
Normalization is a broader concept that encompasses several levels of
normal forms, whereas normal forms are specific rules that define each level
of normalization.
Normalization is an iterative process that involves applying normal forms to a
table until it reaches the desired level of normalization. By achieving higher
levels of normalization, a database can have a more efficient and organized
structure with better data integrity, consistency, and performance.
3. Types of normal forms?
1NF (First Normal Form)
2NF (Second Normal Form)
3NF (Third Normal Form)
BCNF (Boyce-Codd Normal Form)
4NF (Fourth Normal Form)
5NF (Fifth Normal Form)
6NF (Sixth Normal Form)
4. Explain every level of normal forms?
There are several types of normal forms that define the level of
normalization achieved by a database table. Here are the most commonly
used normal forms:
First Normal Form (1NF): This is the most basic level of normalization, and it
requires that each column in a table should contain atomic values, meaning
that a column should not have multiple values in a single row.
Second Normal Form (2NF): This level of normalization requires that a table
should be in 1NF and that all non-key attributes are fully dependent on the
primary key. In other words, there should not be any partial dependencies.
Third Normal Form (3NF): This level of normalization requires that a table
should be in 2NF and that all non-key attributes are independent of each
other. In other words, there should not be any transitive dependencies.
Boyce-Codd Normal Form (BCNF): This form is an extension of 3NF and
requires that every determinant in a table is a candidate key. In other words,
there should not be any non-trivial functional dependencies in a table.
Fourth Normal Form (4NF): This form requires that a table should be in BCNF
and that it should not have any multi-valued dependencies. In other words, a
table should not contain multiple independent many-to-many relationships.
Fifth Normal Form (5NF): This form is also known as Project-Join Normal
Form (PJNF) and requires that a table should be in 4NF and that it should not
have any join dependencies. In other words, a table should not contain any
redundant data that can be derived by joining two or more tables.
5. How the normal form helps to reduce the redundancy?
Normal forms help to reduce redundancy in a database by organizing
data in a way that eliminates duplicate information. This is achieved by
breaking down larger tables into smaller ones and creating relationships
between them using primary keys and foreign keys.
The process of normalization ensures that each piece of data is
stored in only one place, thereby minimizing data duplication. For example, in
a normalized database, customer information might be stored in a separate
table from the orders they have placed. This avoids storing the same
customer information multiple times in the orders table, which reduces
redundancy.
By reducing redundancy, normalization also helps to improve data
consistency and integrity. This is because if data is stored in multiple places,
any changes made to one copy may not be reflected in the other copies,
leading to inconsistencies and data integrity issues.
Overall, normalization helps to create a more efficient and organized
database structure, with reduced data duplication, improved data consistency,
and better performance.
6. What are the primary key and foreign keys? Give an example
In a relational database, a primary key is a unique identifier for
each record in a table. It is a column or set of columns that uniquely identify
each row in a table. A foreign key, on the other hand, is a column or set of
columns in a table that references the primary key of another table. It
establishes a relationship between the two tables and ensures data
consistency and integrity.
Here's an example to illustrate the concept of primary keys and foreign keys:
Let's consider two tables: "Customers" and "Orders". The "Customers" table
contains information about customers, while the "Orders" table contains
information about orders placed by these customers.
The "Customers" table might have columns such as "CustomerID",
"FirstName", "LastName", "Email", and "Phone". Here, the "CustomerID"
column could be set as the primary key since it uniquely identifies each
customer.
The "Orders" table, on the other hand, might have columns such as "OrderID",
"OrderDate", "CustomerID", and "TotalAmount". Here, the "CustomerID"
column is a foreign key that references the "CustomerID" column in the
"Customers" table. This establishes a relationship between the two tables,
indicating that each order in the "Orders" table is associated with a specific
customer in the "Customers" table.
By using primary keys and foreign keys, we can ensure data consistency and
integrity in the database. For example, if a customer is deleted from the
"Customers" table, all associated orders can also be deleted from the
"Orders" table to maintain consistency. Similarly, if a new order is placed, the
"CustomerID" column in the "Orders" table must reference a valid
"CustomerID" in the "Customers" table to maintain integrity.
7. Explain key attributes, non-key attributes, functional dependency, FFD?
Key Attributes: These are attributes that uniquely identify each row in a table.
In other words, they are the columns that make up the primary key of a table.
For example, in a table of employees, the key attributes might be employee ID
or social security number.
Non-Key Attributes: These are attributes that are not part of the primary key
but still provide important information about the entities in the table. For
example, in a table of employees, non-key attributes might include employee
name, address, or salary.
Functional Dependency: This is a relationship between two attributes in a
table, where the value of one attribute determines the value of another
attribute. For example, in a table of orders, the price of an order might be
functionally dependent on the quantity of items ordered.
Full Functional Dependency (FFD): This occurs when an attribute in a table is
functionally dependent on a composite key, meaning that it depends on more
than one key attribute. In other words, it cannot be functionally determined by
any subset of the key attributes. For example, in a table of orders, the price of
an order might be fully functionally dependent on both the quantity ordered
and the item price.
8. What is denormalization ?
Denormalization is the process of adding precomputed redundant
data to an otherwise normalized relational database to improve read performance of
the database. Normalizing a database involves removing redundancy so only a
single copy exists of each piece of information.
9. What is the difference between normalization and de-normalization?
The main difference between the normalization and denormalization
are:-
Normalization aims to reduce redundancy and improve data integrity,
while denormalization introduces redundancy to improve query performance. These
two approaches serve different purposes and should be used selectively based on
the specific needs of the database application.
10. Advantages of using normalization and denormalization?
Advantages of Normalization:
1. Reduced Data Redundancy: Normalization eliminates data redundancy by
breaking larger tables into smaller ones, which helps to improve data consistency
and reduce the potential for data inconsistencies.
2. Improved Data Integrity: Normalization helps to ensure that each piece of data is
stored in only one place, which minimizes duplication and potential inconsistencies,
improving data integrity.
3. Easier Maintenance: Normalization makes it easier to update and modify data,
since each piece of data is stored in only one place.
4.. Better Query Performance: Normalization can improve query performance by
reducing the amount of data that needs to be scanned or joined.
Advantages of Denormalization:
1. Improved Query Performance: Denormalization can significantly improve query
performance by reducing the number of joins and queries needed to retrieve data.
2. Simplified Data Model: Denormalization can simplify the data model, making it
easier to understand and maintain.
3. Faster Data Retrieval: Denormalization can speed up data retrieval by allowing
data to be stored in a format that is optimized for specific queries.
4. Better User Experience: Denormalization can improve the user experience by
reducing the amount of time needed to retrieve data.