You are on page 1of 29

Module 1

1.a) Define Data Base and DBMS.? Explain the architecture of Data Base Management
System in detail with a neat Diagram.?
Answer: Database (DB): A database is a structured collection of data that is organized and
stored in a way that allows for efficient storage, retrieval, and manipulation of the data. It
provides a centralized and controlled environment for managing and accessing data.

Database Management System (DBMS): A DBMS is software that allows users to define,
create, maintain, and manipulate databases. It provides an interface between the users or
applications and the underlying database, enabling efficient storage, retrieval, and
management of data. DBMS handles tasks such as data organization, data integrity, security,
concurrency control, and data recovery.

Architecture of a Database Management System (DBMS):


The architecture of a DBMS typically consists of three main components: the external level,
the conceptual level, and the internal level.
External Level (View Level):
The external level represents the view of the database from the perspective of individual
users or applications. It defines various user views or external schemas that specify how
users can see and access the data. Each user or application can have a different view of the
database, tailored to their specific requirements. The external level provides a high-level
and user-friendly interface for interacting with the database.

Conceptual Level (Logical Level):


The conceptual level represents the overall logical structure and organization of the entire
database. It defines the logical schema, which describes the database structure using high-
level concepts such as entities, relationships, and constraints. The conceptual level provides
a conceptual or abstract view of the database that is independent of any specific
implementation or physical storage details.

Internal Level (Physical Level):


The internal level represents the physical implementation of the database on the storage
media. It deals with the low-level details of how the data is actually stored, indexed, and
accessed on the storage devices. It defines the physical schema, which includes details such
as file organization, indexing techniques, storage allocation, and data compression. The
internal level focuses on optimizing the performance and efficiency of data storage and
retrieval.

1b). Define
a. Meta Data
b. Entity Set
c. Relationship Set
d. Weak Entity Vs Strong Entity
e. Types of attributes.
Answer: a. Meta Data: Meta data refers to the information that describes other data. It
provides context and meaning to the data, allowing users and systems to understand and
interpret it correctly. Meta data can include details such as the structure, format, source,
quality, and relationships of the data.

b. Entity Set: In the context of a database, an entity set is a collection of similar entities. An
entity represents a distinct object, concept, or thing in the real world that can be
distinguished from other objects. For example, in a database for a university, the "Student"
entity set would contain all the individual student entities.
c. Relationship Set: A relationship set defines the association or connection between
entities in a database. It represents the interactions or associations between entities. For
example, in a university database, a "Course" entity set may have a relationship set with a
"Student" entity set, indicating which students are enrolled in which courses.

d. Weak Entity vs Strong Entity: In a database, a strong entity is an entity that has its own
attributes and can exist independently of other entities. It has a unique identifier (primary
key) and does not depend on any other entity for its existence. On the other hand, a weak
entity is an entity that cannot exist without the presence of a related strong entity. It has a
partial key that is used in conjunction with the strong entity's key to uniquely identify it.
Weak entities typically rely on a one-to-many relationship with a strong entity.

e. Types of attributes: There are several types of attributes that can be associated with
entities in a database:
Simple Attribute: A simple attribute represents a single value and cannot be further divided.
For example, the "Age" attribute of a person entity.
Composite Attribute: A composite attribute is made up of multiple simple attributes. It can
be further divided into subparts. For example, the "Address" attribute may consist of sub-
attributes like "Street," "City," and "Zip Code."
Derived Attribute: A derived attribute is derived or calculated from other attributes in the
database. It does not need to be stored explicitly since its value can be determined based
on other attributes. For example, the "Total Price" attribute in a sales order may be derived
from the "Unit Price" and "Quantity" attributes.
Single-Valued Attribute: A single-valued attribute represents a single value for an entity.
Each instance of the entity has only one value for that attribute. For example, the "Date of
Birth" attribute of a person.
Multi-Valued Attribute: A multi-valued attribute can have multiple values for an entity. Each
instance of the entity can have multiple values for that attribute. For example, the "Phone
Numbers" attribute of a person.
Null-Valued Attribute: A null-valued attribute represents the absence of a value for an
entity. It indicates that the attribute value is unknown or not applicable for a particular
instance of the entity.

2 a) Explain the following data models with examples.


i) Relational Data Model
ii) E-R Data Model
iii) Hierarchical Data Model
iv) Network Data Model
Anawer: i) Relational Data Model:
The relational data model is based on the concept of tables or relations. It organizes data
into rows and columns, where each row represents a record or entity, and each column
represents an attribute or property of that entity. The relationships between entities are
represented through key attributes.

ii) E-R Data Model:


The Entity-Relationship (E-R) data model is used to represent the relationships between
entities in a database. It consists of entities, attributes, and relationships. Entities represent
the real-world objects or concepts, attributes define the properties or characteristics of
entities, and relationships describe the associations between entities.
iii) Hierarchical Data Model:
The hierarchical data model organizes data in a tree-like structure with parent-child
relationships. It represents data as a collection of records, where each record can have
multiple child records but only one parent record. The relationships between records are
hierarchical, with a single root record at the top.

iv) Network Data Model:


The network data model is an extension of the hierarchical data model that allows multiple
parent-child relationships between records. It represents data as a collection of records
connected by links. Each record can have multiple parent and child records, forming a
network-like structure.
2 b).Draw the three schema architecture with neat diagram. Why do we need mapping
among the schema levels?
Answer:

External Schema (User View Level):


The external schema represents the view of the database from the perspective of individual
users or applications. It defines different user views or external schemas that specify how
users can see and access the data. Each user or application may have a different view of the
database, tailored to their specific requirements. The external schema provides a high-level
and user-friendly interface for interacting with the database.

Conceptual Schema (Logical Level):


The conceptual schema represents the overall logical structure and organization of the
entire database. It describes the database structure using high-level concepts such as
entities, relationships, and constraints. The conceptual schema provides a conceptual or
abstract view of the database that is independent of any specific implementation or physical
storage details. It acts as a bridge between the external and internal schemas.
Internal Schema (Physical Level):
The internal schema represents the physical implementation of the database on the storage
media. It deals with the low-level details of how the data is actually stored, indexed, and
accessed on the storage devices. The internal schema defines the physical schema, which
includes details such as file organization, indexing techniques, storage allocation, and data
compression. The internal schema focuses on optimizing the performance and efficiency of
data storage and retrieval.
Why do we need mapping among the schema levels?
Mapping between the schema levels is necessary to provide a logical and physical
separation of concerns and to facilitate data independence. Here's why mapping is
important:
 Data Independence: The three-schema architecture allows for data independence,
which means that changes in one schema level should not require changes in other
levels. Mapping provides the necessary abstraction and translation mechanisms to
ensure that modifications in one schema level do not affect the other levels. This allows
for flexibility and ease of maintenance.
 Security and Privacy: Mapping enables the enforcement of security and privacy
policies by controlling access to different schema levels. External schemas can define
different views and access permissions for different users or applications, ensuring that
they can only access the data they are authorized to view or modify.
 Data Integration: Mapping helps integrate multiple external schemas into a unified
conceptual schema. It allows for the consolidation of diverse user views into a coherent
and consistent overall view of the data. Mapping ensures that the external schemas
are aligned with the conceptual schema and any changes made to the conceptual
schema are properly reflected in the external schemas.
 Performance Optimization: Mapping facilitates performance optimization by allowing
the internal schema to be optimized for efficient storage and retrieval of data. It
enables the internal schema to take advantage of indexing, caching, and other
optimization techniques specific to the physical storage system. Mapping ensures that
the logical organization defined in the conceptual schema is appropriately translated
and implemented in the internal schema.

3 a).List and explain with examples the set theory operations used in relational data
Model.
Answer: In the relational data model, several set theory operations are used to manipulate
and combine data from different tables or relations. These operations are based on set
theory concepts and provide powerful capabilities for querying and manipulating data.
The main set theory operations used in the relational data model are:

1. Union (⋃): The union operation combines two sets and returns a new set that
contains all the distinct elements from both sets. In the context of relational databases,
the union operation is used to combine rows from two or more tables, while
eliminating duplicates.
Example:
Consider two tables, "Customers" and "Suppliers," with a common attribute "Name."
The union operation can be used to retrieve a combined list of unique names from both
tables:

2. Intersection (⋂): The intersection operation returns a new set that contains the
common elements present in two or more sets. In the relational data model, the
intersection operation is used to find matching rows between two tables based on
certain criteria.
Example:
Suppose we have two tables, "Employees" and "Managers," both containing the
attribute "EmployeeID." The intersection operation can be used to retrieve the
common employee IDs present in both tables.

This query will return a set of employee IDs that are present in both the "Employees"
and "Managers" tables.

3. Difference (−): The difference operation, also known as set difference or relative
complement, returns a new set that contains the elements present in one set but not
in another set. In the relational data model, the difference operation is used to find
rows that exist in one table but not in another.
Example:
Consider two tables, "Customers" and "VIPCustomers," both with the attribute
"CustomerID." The difference operation can be used to retrieve the customer IDs that
are present in the "Customers" table but not in the "VIPCustomers" table:
This query will return a set of customer IDs that exist in the "Customers" table but are
not present in the "VIPCustomers" table.

4. Cartesian Product (×): The Cartesian product operation combines each element
from one set with every element from another set, resulting in a new set with all
possible combinations. In the relational data model, the Cartesian product operation is
used to generate all possible combinations of rows between two tables.
Example:
Suppose we have two tables, "Products" and "Categories," with attributes "ProductID"
and "CategoryID" respectively. The Cartesian product operation can be used to
generate all possible combinations of products and categories:

5. Projection (π):
The projection operation selects specific attributes from a relation, creating a new relation
with only those selected attributes.
Example:
Given a relation "Students" with attributes "StudentID," "Name," and "Age," the
projection operation can be used to select only the "Name" and "Age" attributes. The
resulting relation will have only those selected attributes.

6. Selection (σ):
The selection operation filters the rows of a relation based on a specified condition,
creating a new relation with only the rows that satisfy the condition.
Example:
Using the "Students" relation, the selection operation can be used to filter out the rows
where the "Age" attribute is greater than 20. The resulting relation will contain only the
student records that meet the specified condition.

3 b).Consider the Company DATABASE: Specify the following queries in relational


algebra:
a. For every project located in ‘Sugarland’, list the project number, the controlling
department number, and the department manager’s last name, address and birth date.
b. For each project, list the project name and the total hours per week (by all employees)
spent of that project.
c. Make a list of project numbers for projects that involve en employee whose last name
is ‘Wong’ either as a manager of the department that controls the project or as a worker.
d. List the names of manager who have at least one dependent.
Answer:

4 a) Explain create, insert, delete and update, drop, alter statements in SQL
with example.
Answer: In SQL (Structured Query Language), there are several statements used for
database management and data manipulation. Here's an explanation of commonly used
SQL statements with examples:
CREATE Statement:
The CREATE statement is used to create a new table, view, index, or other database
objects.
Example: Creating a table named "Students" with columns for student ID, name, and age:

INSERT Statement:
The INSERT statement is used to insert new rows of data into an existing table.
Example: Inserting a new record into the "Students" table:

DELETE Statement:
The DELETE statement is used to remove rows from a table that match a specific condition.
Example: Deleting a record from the "Students" table where the student ID is 1:

UPDATE Statement:
The UPDATE statement is used to modify existing data in a table.
Example: Updating the age of a student in the "Students" table:

DROP Statement:
The DROP statement is used to delete an entire table or other database objects.
Example: Dropping the "Students" table:
ALTER Statement:
The ALTER statement is used to modify the structure of an existing table, such as adding
or dropping columns.
Example: Adding a new column named "GPA" to the "Students" table:

4 b).Consider the following schema for a COMPANY database:


EMPLOYEE(Fname, Lname, SSN, DOB, Sex, Salary, Super_Ssn, Dno)
DEPARTMENT(Dnumber, Dname, Mgr_ssn, mgr_str_date)
DEPT_LOCATION(Dnumber, Dlocation)
PROJECT(Pname, Pnumber, Plocation, Dno)
WORKS-ON(Essn, Pno, Hours)
DEPENDENT(Essn, Depn_name, Sex, Relationship)
Write the relation algebra expressions for the following.
i. Retrieve the names and salary of all employees who works for ‘Finance’
department.
ii. List the names of all employees with two or more dependents.
iii. List all male employees from Dno = 10 and earn less than 50000
Answer:

MODULE -03
5 a).What is a trigger? How is it defined in SQL?Explain with examples?
Answer: In SQL, a trigger is a database object that is associated with a table and
automatically executes a set of actions in response to specific events or conditions.
Triggers are used to enforce data integrity, perform automatic updates, or execute custom
logic whenever certain operations are performed on the associated table.
Triggers are defined using the CREATE TRIGGER statement in SQL, and they are typically
written in the form of SQL statements or procedural code, depending on the database
system.
Here's the general syntax for creating a trigger in SQL:
Let's explain the syntax elements:
 trigger_name: This specifies the name of the trigger.
 {BEFORE | AFTER}: It indicates whether the trigger should be executed before or
after the specified event occurs.
 {INSERT | UPDATE | DELETE}: This specifies the event or operation that will trigger
the execution of the trigger.
 ON table_name: It specifies the table on which the trigger is defined.
 [FOR EACH ROW]: This optional clause indicates that the trigger should be executed
for each affected row.
 trigger_body: It contains the set of SQL statements or procedural code that define
the actions to be performed when the trigger is triggered.

In this example, the trigger named update_timestamp is associated with the employees
table. It is defined to execute before an INSERT operation on the table. The trigger body
updates the created_at column of the new row with the current timestamp.

5 b).Explain JDBC classes and interfaces ?


Answer: JDBC (Java Database Connectivity) is a Java API that provides a standard way for
Java applications to interact with databases. JDBC classes and interfaces form the
foundation of the JDBC API and enable developers to perform various database
operations, such as connecting to a database, executing SQL statements, and retrieving
results. Here are some important JDBC classes and interfaces:
1. DriverManager: The DriverManager class manages the JDBC drivers. It provides
methods to establish a connection to a database using a specific JDBC driver.
2. Connection: The Connection interface represents a connection to a database. It
provides methods to create statements, manage transactions, and retrieve
metadata about the database.
3. Statement: The Statement interface allows executing SQL statements on a
database. It provides methods to execute queries, update data, and retrieve results.
4. PreparedStatement: The PreparedStatement interface extends the Statement
interface and is used to execute parameterized SQL statements. It allows efficient
execution of the same SQL statement with different parameter values.
5. CallableStatement: The CallableStatement interface extends the
PreparedStatement interface and is used to execute stored procedures in the
database. It provides methods to set input and output parameters for the stored
procedure.
6. ResultSet: The ResultSet interface represents the result of a database query. It
provides methods to retrieve data from the query result, navigate through the result
set, and access metadata about the columns.
7. ResultSetMetaData: The ResultSetMetaData interface provides metadata about
the columns in a ResultSet. It allows retrieving information such as column names,
types, and sizes.
8. SQLException: The SQLException class represents an exception that occurred during
database operations. It provides information about the cause of the exception, error
codes, and error messages.

6 a).Explain stored procedures with example.


Answer: Stored procedures are precompiled database routines that are stored and
executed on the database server. They encapsulate a set of SQL statements and
procedural logic, providing a reusable and efficient way to perform complex operations
on the database. Here's an explanation of stored procedures with an example:
Example:
Let's consider a scenario where we have a database table called "Employees" with
columns such as "EmployeeID," "FirstName," "LastName," and "Salary." We want to
create a stored procedure that retrieves employees with a salary above a certain
threshold.
Creating a Stored Procedure:

In this example, we create a stored procedure named "GetHighSalaryEmployees." The


procedure takes a parameter named "threshold," which represents the minimum
salary threshold. The SELECT statement retrieves all employees from the "Employees"
table whose salary is above the specified threshold.
1. Executing the Stored Procedure:
To execute the stored procedure and retrieve the result set, we can use SQL statements
or programming language-specific code. Here's an example using SQL:

In this case, we call the "GetHighSalaryEmployees" stored procedure and pass the
threshold value of 5000. The stored procedure executes on the database server, and
the result set containing the employees with salaries above 5000 is returned.
Stored procedures offer several benefits:
 Code Reusability: Stored procedures can be called from different parts of an
application, avoiding code duplication and promoting maintainability.
 Improved Performance: Stored procedures are precompiled and stored on the
database server. This reduces network traffic and improves query execution
time.
 Enhanced Security: By granting appropriate permissions, applications can
execute stored procedures without exposing underlying table structures or
sensitive data.
 Centralized Logic: Complex business logic can be encapsulated within a stored
procedure, making it easier to manage and modify.
 Transaction Management: Stored procedures can participate in database
transactions, allowing for consistent and atomic operations.

6 b).Draw the neat diagram of single, two, three tier architecture diagrams. Explain
thefunctional components in those architectures.
Answer:
Single-Tier Architecture (also known as Standalone Architecture):
In a single-tier architecture, the entire application is implemented on a single machine,
where the user interface, application logic, and database are all hosted together. Here
is a diagram illustrating the components of a single-tier architecture:
Functional Components:
 User Interface: This component is responsible for interacting with the end-users. It
includes the presentation layer, which handles the display of information and receives
user input.
 Application Logic: The application logic component contains the business logic and
processing rules of the application. It performs the necessary computations, data
manipulation, and decision-making based on the user input and interactions.
 Database: The database component stores and manages the data required by the
application. It handles data persistence, retrieval, and management operations.
Two-Tier Architecture (also known as Client/Server Architecture):
In a two-tier architecture, the application is divided into two major components: the
client and the server. The client handles the user interface and application logic, while
the server manages the database operations. Here is a diagram illustrating the
components of a two-tier architecture:
Functional Components:
 User Interface: The user interface component, similar to the single-tier architecture,
handles the presentation layer and user interactions.
 Application Logic: In a two-tier architecture, the application logic is primarily located
on the client machine. It communicates with the server to retrieve and store data,
perform business operations, and handle user requests.
 Database: The database component resides on the server machine and manages the
storage and retrieval of data. It responds to the client's requests for data manipulation
and retrieval.
Three-Tier Architecture:
In a three-tier architecture, the application is divided into three layers: presentation,
application, and data layers. The layers are typically deployed on separate machines or
servers. Here is a diagram illustrating the components of a three-tier architecture:

Functional Components:
User Interface: The user interface component handles the presentation layer and user
interactions, similar to the previous architectures.
Application Logic: In a three-tier architecture, the application logic resides on the application
server. It processes user requests, performs business operations, and communicates with the
database server to retrieve or store data.
Database: The database component is located on the database server. It manages the
storage, retrieval, and manipulation of data. The application server interacts with the
database server to retrieve or update data based on user requests.
MODULE -04
7 a).Define Normal Form. Explain 1NF, 2NF, 3NF with suitable Examples
Answer: The following are the first, second, and third normal forms (1NF, 2NF, and 3NF),
along with explanations and examples:
1. First Normal Form (1NF): The first normal form requires that each attribute in a table must
have atomic (indivisible) values, and there should be no repeating groups or arrays of data. In
other words, the table should be "flat" with no nested or repeating data.
Example: Consider a table called "Employee" with the following columns: Employee ID,
Name, and Skills. In its current state, the "Skills" column contains multiple values separated
by commas, like "Java, SQL, Python." To achieve 1NF, we need to separate the skills into
individual rows, creating a new table called "EmployeeSkills" with the columns: Employee ID
and Skill.

2. Second Normal Form (2NF): The second normal form builds upon the first normal form
and requires that every non-key attribute in a table is functionally dependent on the whole
primary key, rather than just part of it. In simpler terms, it eliminates partial dependencies by
ensuring that each attribute depends on the entire primary key, not just a portion of it.
Example: Consider a table called "OrderDetails" with the columns: Order ID, Product ID,
Product Name, and Quantity. The primary key is a composite key consisting of Order ID and
Product ID. In this case, the "Product Name" attribute depends only on the Product ID, not
on the entire composite key. To achieve 2NF, we split the table into two: "Orders" with Order
ID as the primary key, and "Products" with Product ID and Product Name.

3. Third Normal Form (3NF): The third normal form further refines the normalization process
by ensuring that there are no transitive dependencies. A transitive dependency occurs when
an attribute depends on another non-key attribute, rather than directly on the primary key.
Example: Consider a table called "StudentCourses" with the columns: Student ID, Course ID,
Course Name, and Instructor. In this case, the "Instructor" attribute depends on the "Course
ID," which is not part of the primary key but dependent on the "Student ID." To achieve 3NF,
we split the table into three: "Students" with Student ID as the primary key, "Courses" with
Course ID as the primary key, and "CourseInstructors" with Course ID and Instructor.
4. Fourth Normal Form (4NF): 4NF addresses the issue of multi-valued dependencies. A table
is in 4NF if it is in 3NF and has no non-trivial multi-valued dependencies.
Example: Consider a table called "Employee" with the following columns: Employee ID,
Employee Name, Project ID, Project Name, and Skill. The primary key is Employee ID. In this
table, a single employee can be associated with multiple projects, and each project may have
multiple skills. This creates a multi-valued dependency between Project ID and Skill. To bring
the table into 4NF, it can be split into three tables: Table
1. "Employees" with columns:
Employee ID (primary key), Employee Name
2: "Projects" with columns:
Project ID (primary key), Project Name
3: "Skills" with columns:
Employee ID (foreign key referencing Employees table), Project ID (foreign key referencing
Projects table), Skill By splitting the table into these three tables, we eliminate the multi-
valued dependency and ensure that each table contains only atomic values.

5. Fifth Normal Form (5NF): 5NF, also known as Project-Join Normal Form (PJNF), deals with
the issue of join dependencies. A table is in 5NF if it is in 4NF and has no non-trivial join
dependencies based on the primary key.
Example: Consider a table called "StudentCourses" with the following columns: Student ID,
Course ID, Student Name, Course Name, and Instructor. The primary key is (Student ID, Course
ID). In this table, there is a join dependency between Student ID and Course Name, and
another join dependency between Course ID and Instructor. To achieve 5NF, the table can be
split into four tables:
Table 1:
"Students" with columns: Student ID (primary key), Student Name
Table 2:
"Courses" with columns: Course ID (primary key), Course Name
Table 3:
"StudentCourses" with columns: Student ID (foreign key referencing Students table), Course
ID (foreign key referencing Courses table)
Table 4:
"CourseInstructors" with columns: Course ID (foreign key referencing Courses table),
Instructor.
7 b).What do you mean by multivalued dependency?Describe 4NF with example.
Answer: A multivalued dependency (MVD) is a concept in database normalization that
represents a relationship between attributes in a table. It occurs when a table contains two
or more sets of attributes that are independent of each other, meaning that the values of one
set of attributes do not determine or affect the values of the other set(s).
In other words, a multivalued dependency arises when a table has attributes that can have
multiple values for a single combination of values in the other attributes. This implies that the
attributes exhibit a non-functional dependency, where changes in one attribute do not
determine changes in the other attribute(s).
The notation used to represent a multivalued dependency is X ->-> Y, where X and Y are sets
of attributes. 4This notation indicates that for every combination of values in X, there can be
multiple corresponding combinations of values in Y.To better understand, consider an
example:
Table: Employee
| Employee ID | Skills |
| 1 | Java, SQL | | 2 | Python, Java | | 3 | SQL, C# |
In this example, the table "Employee" has two attributes: Employee ID and Skills. The Skills
attribute represents the skills possessed by each employee. Notice that an employee can have
multiple skills, and multiple employees can have the same skill. Here, a multivalued
dependency exists between Employee ID and Skills. For a given Employee ID, there can be
multiple combinations of Skills.
To remove the multivalued dependency, we can normalize the table by splitting it into two
tables: "Employees" and "Skills." The "Employees" table will contain the Employee ID
attribute, while the "Skills" table will contain the Employee ID and the corresponding skills.
This separation eliminates the multivalued dependency and results in a more structured and
normalized database design.

8 a).Define Minimal cover. Write an algorithm for finding a minimal cover G fora set of
functional dependencies F.
Answer: Minimal cover, also known as canonical cover, is a concept in database normalization
that represents a minimal set of functional dependencies necessary to preserve all the
dependencies of a given set of functional dependencies (F). It eliminates redundant or
extraneous dependencies, resulting in a compact representation.
Algorithm for finding a minimal cover G for a set of functional dependencies F:
1. Start with the original set of functional dependencies F.
2. Remove any extraneous attributes from the left-hand side (LHS) of each functional
dependency. To do this, for each functional dependency X -> Y in F:
a. For each attribute A in X:
i. Remove A from X.
ii. If X -> Y is still implied by the remaining functional dependencies, keep the modified X;
otherwise, restore A to X.
b. Repeat step 2a until no more extraneous attributes can be removed from any X.

3. Remove any redundant functional dependencies. To do this, for each functional


dependency X -> Y in F:
a. Remove X -> Y from F.
b. If X+ (the closure of X under F) still includes Y, discard the dependency; otherwise, keep the
dependency.
4. Repeat steps 2 and 3 until no more changes are made to F.
5. The resulting set of functional dependencies is the minimal cover G.

8 b).Given below are two sets of FD’s for a relation R (A, B, C, D, E, H).Are they
equivalent?F= {A->C, AC->D, E->AD, E->H} and G= {A->CD, E->AH}
Answer: To determine if two sets of functional dependencies (FDs) are equivalent, we need
to check if they imply the same closure for each attribute or attribute set.
Let's compare the sets of functional dependencies F and G:
F = {A->C, AC->D, E->AD, E->H}
G = {A->CD, E->AH}
To check for equivalence, we need to compute the closure of attributes for each set of FDs
and compare the results.
Compute the closure of attributes for F:
A+ = ACDH (A is a candidate key)
B+ = B (B is not on the left-hand side of any FD)
C+ = C (C is not on the left-hand side of any FD)
D+ = D (D is not on the left-hand side of any FD)
E+ = AECDH (E is a candidate key)
H+ = H (H is not on the left-hand side of any FD)
Compute the closure of attributes for G:
A+ = ACD (A is a candidate key)
B+ = B (B is not on the left-hand side of any FD)
C+ = C (C is not on the left-hand side of any FD)
D+ = D (D is not on the left-hand side of any FD)
E+ = AEH (E is a candidate key)
H+ = H (H is not on the left-hand side of any FD)
Comparing the closures, we can see that for each attribute or attribute set, the closures are
the same in F and G. Therefore, F and G have equivalent sets of functional dependencies.

MODULE -05
9 a) .List and explain ACID Properties.?
Answer: In database systems, a transaction refers to a logical unit of work that consists of one
or more database operations. These operations are performed as a single indivisible unit,
ensuring the consistency, integrity, and reliability of the database.
ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. These
properties define the desirable characteristics that a transaction should exhibit. Let's discuss
each of the ACID properties in detail:

1. Atomicity: Atomicity ensures that a transaction is treated as an all-or-nothing operation. It


means that either all the operations within the transaction are successfully completed, or
none of them are applied to the database. There should be no partial execution of a
transaction. If any operation within the transaction fails, all changes made by the transaction
are rolled back, and the database is restored to its state prior to the transaction.
For example, consider a transaction that transfers funds from one bank account to another.
Atomicity ensures that if the debit operation (deducting funds from one account) is successful
but the subsequent credit operation (adding funds to the other account) fails, the entire
transaction is rolled back, and both accounts remain unaffected.
2. Consistency: Consistency ensures that a transaction brings the database from one valid
state to another. It ensures that all data modifications within a transaction adhere to the
defined integrity constraints and rules of the database. The database remains in a consistent
state before and after the transaction.
For example, if a database has a constraint that specifies that all email addresses must be
unique, any transaction attempting to insert duplicate email addresses would violate the
consistency property. The database management system (DBMS) must prevent such
transactions from committing to maintain data consistency.

3. Isolation: Isolation ensures that concurrent execution of multiple transactions produces


the same result as if the transactions were executed serially, one after another. Each
transaction is executed in isolation, unaware of the existence of other concurrently executing
transactions. Isolation prevents interference between concurrent transactions, avoiding data
inconsistencies and ensuring transaction integrity. Isolation is achieved through various
concurrency control mechanisms, such as locking, to control access to shared data and
maintain data integrity
For example, if two transactions simultaneously read and modify the same data, isolation
mechanisms ensure that the changes made by one transaction do not interfere with the other
transaction until it is committed.

4. Durability: Durability guarantees that once a transaction is committed, its effects or


changes to the database persist even in the event of system failures (such as power outages
or crashes). The changes made by a committed transaction become permanent and are
stored in non-volatile memory, ensuring data durability.
To ensure durability, DBMSs typically use techniques like write-ahead logging or database
backups. These techniques allow the system to recover the database state to the last
consistent state before a failure occurred.
For example, once a transaction is committed, a successful funds transfer operation should
persist in the database even if the system crashes immediately after the commit.
9 b). What are the anomalies that can occur due to concurrent execution of transactions?
Explain them with example.
Answer: Anomalies that can occur due to concurrent execution of transactions in a database
system are known as concurrency control anomalies. The main anomalies that can arise are:
 Lost Update:The lost update anomaly occurs when two or more transactions
concurrently update the same data, and one of the updates is lost. It happens when
the changes made by one transaction are overwritten by another transaction before
they are committed. This can result in data inconsistency.
Example:
Consider two transactions T1 and T2. The initial value of a variable X is 10
T1: Reads the value of X as 10.
T2: Reads the value of X as 10.
T1: Updates the value of X to 20.
T2: Updates the value of X to 30.
T1: Commits the transaction.
T2: Commits the transaction.
In this scenario, the update made by T1 (20) is lost, and the final value of X becomes 30. The
update made by T2 overwrites the update made by T1, leading to data inconsistency.

 Dirty Read:The dirty read anomaly occurs when one transaction reads uncommitted
changes made by another transaction. It happens when a transaction reads data from
a row that has been modified by another transaction but not yet committed. If the
modifying transaction rolls back, the reading transaction will have read invalid or
incorrect data.
Example:
Consider two transactions T1 and T2. The initial value of a variable X is 10.
T1: Reads the value of X as 10.
T2: Updates the value of X to 20 but does not commit.
T1: Reads the value of X again and gets the uncommitted value of 20.
In this case, T1 reads the uncommitted value of X, which can lead to incorrect calculations or
decisions based on incomplete or incorrect data.
 Non-Repeatable Read:The non-repeatable read anomaly occurs when a transaction
reads the same data twice but gets different values due to other concurrent
transactions modifying the data in between. It results in inconsistency and unexpected
behavior.
Example:
Consider two transactions T1 and T2. The initial value of a variable X is 10.
T1: Reads the value of X as 10.
T2: Updates the value of X to 20 and commits.
T1: Reads the value of X again and gets the updated value of 20.
In this scenario, T1 reads the value of X twice but gets different values due to the update
made by T2. This inconsistency can lead to incorrect analysis or processing of data.

10 a). Define deadlock and Starvation. Explain the deadlock prevention and detection
protocols.
Answer:
 Deadlock:
Deadlock refers to a situation in concurrent systems where two or more processes are unable
to proceed because each is waiting for a resource that is held by another process in the set.
This creates a circular dependency, causing all the processes involved to become stuck
indefinitely. Deadlock can result in a complete system halt and is a significant issue in multi-
process or multi-threaded environments.

 Starvation:
Starvation occurs when a process is unable to access a required resource or enter a specific
section of code due to being perpetually blocked or delayed by other processes. It is a form
of resource allocation problem where a process keeps waiting for a resource but is unable to
acquire it. While the system continues to function, the starved process is unable to make
progress.

Deadlock Prevention:
Deadlock prevention aims to avoid the occurrence of deadlocks by ensuring that at least one
of the necessary conditions for deadlock cannot be met. The two common approaches to
deadlock prevention are:
 Mutual Exclusion: Resources that are not shareable must be assigned exclusively to
one process at a time. By ensuring mutual exclusion, the possibility of circular wait and
deadlock is eliminated.
 Resource Ordering: Define a total ordering of resources and require processes to
request resources in a specific order. By avoiding circular wait scenarios, the chance
of deadlock is minimized.
Deadlock Detection:
Deadlock detection involves periodically checking the system for the presence of deadlocks.
The system maintains a wait-for graph, which represents the resources held and requested
by processes. Two popular deadlock detection algorithms are:
 Resource Allocation Graph (RAG) Algorithm: It utilizes a directed graph called a
resource allocation graph to represent the resource allocation and resource request
relationships among processes. Deadlocks can be detected by analyzing the cycles in
the graph.
 Banker's Algorithm: This algorithm is used to determine whether a system is in a safe
state or an unsafe state. It simulates resource allocation scenarios and checks if there
exists a sequence of process execution that can complete without entering a deadlock
state. If such a sequence exists, the system is in a safe state; otherwise, it is in an unsafe
state.

10 b).How to recover the transaction from failure? Explain the list of recovery concepts.

Answer: Recovering a transaction from failure involves restoring the system and the data
to a consistent state after a failure has occurred. The recovery process typically consists of
several concepts and techniques to ensure data integrity and minimize the impact of
failures. Here is a list of recovery concepts commonly used:

1. Undo Logging:
 Each transaction operation is logged before it is applied to the database.
 During recovery, the log is analyzed in reverse order, and the operations are undone
(rolled back) to restore the state before the transaction.
 This ensures that the changes made by incomplete or failed transactions are
reverted.
2. Redo Logging:
 After a transaction operation is successfully applied to the database, it is logged.
 During recovery, the log is analyzed, and the logged operations are redone to bring
the database to a consistent state.
 This ensures that committed transactions are properly reapplied in case of failure.
3. Write-Ahead Logging (WAL):
 A technique where changes are written to the log before they are written to the
database.
 The log ensures that before a transaction's changes are applied, the corresponding
log entries are persisted, providing durability and recovery capabilities.
 During recovery, the log is used to determine which changes need to be undone or
redone.
4. Checkpoints:
 Periodically, a checkpoint is created to record the state of the system at a specific
point in time.
 Checkpoints reduce the recovery time by providing a known stable state from which
the recovery process can start.
 During recovery, only the transactions that were active after the last checkpoint
need to be analyzed and recovered.
5. Shadow Paging:
 A recovery technique where a shadow copy of the database is created and
maintained during the execution of transactions.
 The shadow copy represents a consistent state of the database before any changes
were made.
 In case of failure, the shadow copy is used to restore the database to a consistent
state by discarding the changes made after the last shadow copy.
6. Write-Ahead Logging with Checkpoints (WALC):
 A combination of write-ahead logging and periodic checkpoints.
 Changes are written to the log before they are applied to the database, ensuring
durability.
 Periodic checkpoints record the state of the system, reducing the recovery time.
7. Crash Recovery:
 A process that takes place during system startup after a crash or failure.
 It involves analyzing the log and performing necessary undo and redo operations to
restore the system to a consistent state.

You might also like