DBMS Chit Something
DBMS Chit Something
Part-A questions:
Q1. Advantages of DBMS:
Data redundancy control, improved data sharing, data security, backup and
recovery, data integrity, concurrency control, easy data access, centralized
management.
Part-A questions:
Q4. What are the three types of anomalies? Explain with suitable examples.
Insertion (adding data causes issues), Deletion (removing data causes loss),
Update (inconsistent data). E.g., deleting employee deletes department info.
- PART-B
Q.1 (a) State and explain various features of E-R Models.
| Name | | Title |
Example:
SELECT e1.Name
FROM Employees e1
WHERE Salary > (SELECT AVG(Salary) FROM Employees e2 WHERE e1.DeptID =
e2.DeptID);
Here, the subquery depends on the DeptID of each outer row. It calculates the
average salary per department and filters employees with higher salaries than
their departmental average.
Such queries are useful for comparisons within groups or related data.
However, they can be slow due to multiple subquery executions.
Q.3 Explain about Selection, Projection, Rename, Division and Cartesian
product operations in relational-algebra with suitable examples?
AH adds H.
From ABC and BDEF, we get all attributes: A, B, C, D, E, F, G, H.
Candidate Key: ABC.
Q.4 (b) Determine the closer of the following set of functional dependencies
for a relational scheme RA, B, C, D) and FDs{ABC,CD,DA). List out the
candidate keys of R.
Given:
R = (A, B, C, D)
F = {ABC, CD, DA}
Closure of ABC:
ABC gives A, B, C.
CD not triggered as D missing.
DA not triggered.
ACID Properties:
Atomicity: All operations in a transaction complete or none do.
Consistency: Ensures the database remains in a valid state before and
after the transaction.
The closure of F (F⁺) is the set of all functional dependencies that can be
inferred from a given set F using inference rules (Armstrong’s axioms:
Reflexivity, Augmentation, and Transitivity).
Computing F⁺ involves iteratively applying these rules to discover all implied
dependencies.
Example:
Given F = {A → B, B → C},
Then:
A → B (given)
B → C (given)
A → C (by transitivity)
So F⁺ = {A → B, B → C, A → C}
F⁺ is useful in normalization and determining candidate keys
Part-B
To find the sum of salaries of all employees using relational algebra, we can use
the aggregate function SUM. Given the relation Employee(Name, Salary,
Dept_no), the relational algebra expression is:
SUM_Salary ← 𝛾 SUM(Salary)(Employee)
Explanation:
The gamma (𝛾) operator is used for aggregation. Here, 𝛾 SUM(Salary) performs
the summation of the Salary attribute for all tuples in the Employee relation.
This expression returns a single tuple with the total salary paid to all
employees, regardless of department.
If we also want to find the sum of salaries grouped by department, the
expression becomes:
To count the number of employees in each department using SQL, we use the
GROUP BY clause with the COUNT() function. The query is:
FROM Employee
GROUP BY Dept_no;
Explanation:
This query counts how many employees are present in each department. The
GROUP BY Dept_no groups the employee records based on the department
number. The COUNT(*) function counts all the tuples (rows) in each group,
effectively providing the number of employees in each department.
If you want to include department names from the Department table as well,
you can join the two tables:
SELECT D.Dept_name, E.Dept_no, COUNT(*) AS Employee_Count
FROM Employee E
JOIN Department D ON E.Dept_no = D.Dept_no
To get the name of the employee with the highest salary in each department,
we can use a correlated subquery or ROW_NUMBER() function. Here’s a
standard SQL query using a subquery:
SELECT Name, Salary, Dept_no
FROM Employee E
WHERE Salary = (
SELECT MAX(Salary)
FROM Employee
WHERE Dept_no = E.Dept_no
);
Explanation:
This query finds employees whose salary is the maximum within their
department. For each employee E, the subquery finds the maximum salary in
E's department. If E’s salary matches that maximum, the employee is selected.
If multiple employees have the same highest salary in a department, they all
will be included.
Alternatively, using window functions (if supported):
SELECT Name, Salary, Dept_no
FROM (
SELECT Name, Salary, Dept_no,
RANK() OVER (PARTITION BY Dept_no ORDER BY Salary DESC) AS rnk
FROM Employee
) AS Ranked
WHERE rnk = 1;
This version ranks employees within departments by salary and selects those
ranked 1.
3. Enrollment(RollNo, CourseCode)
This decomposition eliminates redundancy and anomalies, ensuring each non-
prime attribute is fully dependent on a whole candidate key.
T1 reads A
T2 reads A
T2 updates A
T1 subtracts 100 and updates A → incorrect final A balance
Schedule 2 (Serializable):
T1 completes
T2 starts → result is correct
A schedule is conflict-serializable if it can be transformed into a serial schedule
by swapping non-conflicting operations. Serializability ensures data consistency
by avoiding race conditions or inconsistent reads/writes.
Q.6 Why is a transaction required to be atomic ? Explain using suitable
A transaction is required to be atomic to ensure that it is all-or-nothing. Either
all operations in a transaction are completed successfully, or none are. This is
one of the ACID properties of transactions (Atomicity, Consistency, Isolation,
Durability).
Example:
Consider a fund transfer between two accounts:
Purpose of Views:
1. Data Abstraction: Hide complexity of joins or calculations by simplifying
queries for users.
2. Security: Restrict user access to specific columns or rows of a table.
Example: A view may expose only employee names and departments but not
salaries.
3. Logical Data Independence: Base tables can change without affecting
user interaction, as long as the view remains valid.
1. Two-Tier Architecture
Structure:
Client Tier: User interface (e.g., desktop application).
Database Tier: Database server that handles data storage and query
processing.
How it works:
2. Three-Tier Architecture
Structure:
Application Tier (Middle Layer): Application server that handles business logic.
Data Tier (Database): Database server that stores and retrieves data.
How it works:
The client communicates with the application server, which then
communicates with the database.
Why?
Separation of Concerns
Divides responsibilities: UI, business logic, and data access are all handled in
separate layers.
This improves maintainability and scalability.
Improved Security, Direct access to the database is restricted.
The application server can implement access control, input validation, and
authentication.
Scalability
Q.2
a) List three reasons why null values might be introduced into the
database.
Here are three common reasons why NULL values might be introduced into a
database:
) Fine-Grained Control
a) Developers can control the exact sequence of operations, which is
useful for complex logic, algorithms, or data manipulation.
b) General-Purpose Use
c) Well-suited for a wide variety of programming tasks, from desktop
apps to system-level programming.
d) Strong Support for Control Structures
e) Includes loops, conditionals, and functions, enabling detailed
control of flow and logic.
f) Widely Known and Supported
g) Most programmers are trained in procedural languages, and
there's extensive community and library support.
Nonprocedural (Declarative) Languages (e.g., SQL, Prolog, HTML)
Merits:
h) Focus on What, Not How
i) The user specifies what outcome is desired, and the system
determines how to achieve it. This leads to simpler and more
readable code.
j) Less Code, Higher Productivity
k) Tasks that would require many lines of procedural code can often
be accomplished with one or two lines of declarative code.
n) Reduced Errors
o) By hiding procedural logic, there's less room for implementation
errors, especially for repetitive or complex operations. Comparison
Summary Table:
Nonprocedural
Feature Procedural Languages
Languages
Control over
High Low
execution
Nonprocedural
Feature Procedural Languages
Languages
SELECT *
FROM student
NATURAL FULL OUTER JOIN takes
NATURAL FULL OUTER JOIN course;
Q.2 d) Suppose user A, who has the authorizations on a relation r,
grants select on relation r to public with grant option. Suppose user B
then grants select on r to A. Does this cause a cycle in the authorization
graph? Explain why.
No, this does not create a cycle in the authorization graph.
Here's why:
User A already has full rights on relation r and can grant those rights to others.
User B got the SELECT right from A (through PUBLIC) and then gave it back to A.
But A didn’t need B’s grant—A already had the right independently.
So, A does not depend on B, which means there is no cycle. A cycle only
happens if users depend on each other for their privileges, which isn’t the case
here.
Q.3 Explain the purpose of the checkpoint mechanism. How often should
checkpoints be performed? How does the frequency of checkpoints affects?
a) System performance when no failure occurs?
a) Compute B+,
b) Prove (using Armstrong's axioms) that AF is a superkey.
c) Compute a canonical cover from the above set of functional
dependencies F; give each step of your derivation with an
explanation.
d) Give a 3NF decomposition of r based on the canonical cover.
e) Give a BCNF decomposition of r using the original set of
functional dependencies.
To address the problem, we will go through each part step by step.
1. Compute \( B^+ \)
- \( BC \rightarrow DE \)
- \( B \rightarrow D \)
- \( D \rightarrow A \)
$$
F_c = \{ A \rightarrow BCD, BC \rightarrow DE, B \rightarrow D, D \rightarrow A
\}
$$
- \( R_1(A, B, C, D) \)
- \( R_2(B, C, D, E) \)
- \( R_3(B, D) \)
- \( R_4(D, A) \)
- \( R_1(A, C) \)
- \( R_2(B, D) \)
- \( R_3(A, E, F) \)
1. Ensuring Serializability:
Serializability means that even if multiple transactions run at the same time,
the end result is the same as if they ran one after the other (in some order).
Read-only transactions don’t change data, so they don’t block each other
when they lock data.
Update transactions lock data in a strict order (starting with the root), which
prevents any confusion about which transaction should go first. This ordered
process means their actions can be rearranged to look like they were done one
at a time (serially).
Result: The protocol makes sure transactions are serializable (the final
outcome is the same as if they were done one at a time).
Partc
Q1 Explain the various types of joins in SQL, Give suitable examples for each
type.
1. INNER JOIN
Retrieves only the matching rows from both tables based on the join condition.
If there is no match, the row is excluded from the result.
2. LEFT JOIN (or LEFT OUTER JOIN)
Retrieves all rows from the left table, and the matching rows from the right
table.
If there is no match in the right table, NULL is returned for those columns.
3. RIGHT JOIN (or RIGHT OUTER JOIN)
Retrieves all rows from the right table, and the matching rows from the left
table.
If there is no match in the left table, NULL is returned for those columns.
Retrieves all rows when there is a match in either left or right table.
If there is no match on one side, NULL is returned for the missing values.
5. CROSS JOIN
Returns the Cartesian product of both tables.
Every row from the first table is paired with every row from the second table.
6. SELF JOIN
A table is joined with itself.
Enrollment(StudentID, Course)
In Course_Info,
InstructorPhone depends on InstructorName, not directly on Course →
Transitive dependency.
Decompose into:
Course(Course, InstructorName)
Instructor(InstructorName, InstructorPhone)
Student(StudentID, Name)
Enrollment(StudentID, Course)
Course(Course, InstructorName)
Instructor(InstructorName, InstructorPhone)
Conflict Serializability
Conflict serializability ensures that a schedule can be transformed into a serial
schedule by swapping non-conflicting operations.
It is based on conflicting operations like read-write, write-read, and write-write
on the same data item.
View Serializability
View serializability ensures that a schedule is view-equivalent to a serial
schedule.
It considers the final outcome of transactions (i.e., the values read and written)
rather than the order of operations.
🔹 Purpose of Indexing
🔹 Types of Indexes
🔹 Advantages
🔹 Disadvantages
Q 8 What are B-trees and why do DBMS use then? Explain with
examples.
What are B-Trees in DBMS: A B-Tree is a self-balanced tree data structure used
in databases and file systems to maintain sorted data and allow searches,
insertions, deletions, and sequential access in logarithmic time.
Balanced Structure
Fast Searching
B-Trees reduce the number of disk I/O operations needed to locate a record.
Dynamic Growth
B-Trees can grow or shrink efficiently as data is inserted or deleted.
Key Features of B-Trees
Example (Theory)
Suppose a B-Tree of order 3 is used:
3. AVG()
Calculates the average value of a numeric column.
SELECT AVG(column_name) FROM table_name;
4. MAX()
Finds the maximum value in a column.
5. MIN()
Finds the minimum value in a column.
Q1. Draw the diagram of system structure of DBMS. Write down the main
functions of each component. Discuss its types.
... [Q1, Q2, Q3 already included above] ...
Q4. Explain Embedded SQL and its need. How it is different from Dynamic
SQL?
Embedded SQL is a method of combining the computing power of a high-level
programming language (like C, Java) with SQL's powerful database
manipulation capabilities. In embedded SQL, SQL statements are directly
written within the host language code and are preprocessed before
compilation.
Example:
EXECUTE IMMEDIATE 'SELECT * FROM employee WHERE dept = ''' ||
deptName || '''';
Differences:
Compilation
At compile time At runtime
Time
Use Cases:
Embedded SQL is preferred for predefined queries.
Dynamic SQL is suitable for applications requiring ad-hoc query
generation.
Q5. What is trigger? What is the difference between a trigger and procedure?
A trigger is a set of SQL statements that automatically executes in response to
certain events on a table or view, such as INSERT, UPDATE, or DELETE. Triggers
help enforce business rules, ensure data consistency, and maintain audit trails.
Syntax Example:
CREATE TRIGGER audit_log
AFTER INSERT ON employee
FOR EACH ROW
BEGIN
Key Points:
Triggers are bound to table events.
Procedures must be explicitly called.
Q1. Draw the diagram of system structure of DBMS. Write down the main
functions of each component. Discuss its types.
|
v
+----------------------+
| Query Processor |
+----------------------+
| - Parser |
| - Translator |
| - Optimizer |
+----------+-----------+
+----------------------+
| Execution Engine |
+----------+-----------+
|
+----------------------+
| Storage Manager |
+----------------------+
| - Transaction Mgr |
| - Buffer Mgr |
| - File Mgr |
| - Recovery Mgr |
| - Authorization Mgr |
+----------+-----------+
|
v
+----------------------+
| Physical DB |
+----------------------+
Main Components and Functions:
1. Query Processor:
o Translates high-level SQL queries into a form the system can
execute.
2. Execution Engine:
o Executes the optimized query plan and communicates with the
storage manager.
3. Storage Manager:
4. Physical Database:
o Actual storage where data is saved on disk.
Types of DBMS:
1. Hierarchical DBMS: Data is organized in a tree-like structure. Example:
IBM IMS.
2. Network DBMS: Data is organized in graph structure, supports many-
to-many relationships.
3. Relational DBMS: Uses tables with rows and columns. Example:
MySQL, Oracle.
4. Object-Oriented DBMS: Supports object storage, inheritance. Example:
db4o, ObjectDB.
Q3. Differences Between File System and Relational Database with Examples
File System:
A file system stores data in files or folders on disk. It is simple and widely
used but lacks sophisticated data management features. Files can be text,
binary, or structured but without enforced relationships or constraints.
Data Storage: Data stored in flat files like CSV, text files, or
spreadsheets.
Data Redundancy: High chance of duplicate data since no centralized
control.
Data Access: Sequential or random file access using file pointers.
None (manual or
Query Language SQL
programmatic)
Data
High Low (through normalization)
Redundancy
Concurrent
Limited Supported with locking
Access
Automatic recovery
Recovery Manual
mechanisms
In summary, file systems are simple but limited; relational DBMS provide
structured, reliable, and efficient data management suitable for complex
applications.
Q4. Explain Embedded SQL and its need. How is it different from Dynamic
SQL?
Embedded SQL is a technique where SQL statements are embedded directly
into a host programming language like C, C++, or Java. It allows programs to
execute SQL commands seamlessly with procedural code. The embedded SQL
statements are pre-compiled by a preprocessor that translates SQL into calls to
the database management system.
Need for Embedded SQL:
To combine the power of SQL’s data manipulation capabilities with the
programming logic of a host language.
To allow SQL statements to be written inside application programs,
enabling interaction with databases.
Provides compile-time syntax checking of SQL statements for error
detection early in development.
Q6. Give formal definitions and explain with example with respect to:
a) Division Operation:
The division operator ÷ in relational algebra returns tuples from one relation
that are related to all tuples of another relation. For example, find students
who have taken all courses offered.
If R(A, B) and S(B) are relations, then R ÷ S returns all A values from R related to
all B in S.
b) Set Operations:
Union (∪): Combines tuples from both relations, removing duplicates.
Intersection (∩): Tuples common in both relations.
Q7. Define normalization. Explain 1NF, 2NF, 3NF and BCNF with example.
Normalization is the process of organizing data in a database to reduce
redundancy and improve data integrity by dividing tables and defining
relationships.
1NF (First Normal Form):
Each attribute contains atomic values; no repeating groups.
Example: Table with multi-valued phone numbers violates 1NF; split into
separate rows.
2NF (Second Normal Form):
In 1NF and every non-key attribute is fully functionally dependent on the
primary key (no partial dependency).
Example: If a table with composite key (A, B) has attribute depending
only on A, it violates 2NF.
3NF (Third Normal Form):
In 2NF and no transitive dependency exists, i.e., non-key attributes
depend only on the key.
Example: If attribute C depends on B, which depends on key A, it violates
3NF.
BCNF (Boyce-Codd Normal Form):
Stronger than 3NF; every determinant is a candidate key.
Handles anomalies not covered by 3NF.
Augmentation: If X → Y, then XZ → YZ
Transitivity: If X → Y and Y → Z, then X → Z
ii) Closure of a set of functional dependencies:
All functional dependencies that can be inferred from a given set using
Armstrong’s axioms.
Q9. Decompose the schema R= (A, B, C, D, E) into (A, B, C) and (A, D, E). Also
show that this decomposition is lossless-join decomposition if the following
FDs hold: A→BC, CD→E, B→D, E→A.
Given:
R = (A, B, C, D, E)
Decomposition: R1 = (A, B, C), R2 = (A, D, E)
Here:
A → BC (from F) so A → R1
A → DE can be inferred from B→D, E→A, and other FDs?
Check closure of A: A+ = {A, B, C} (from A→BC), and B→D implies A→D
via augmentation. Also E→A implies E+ includes A, so from CD→E and
B→D, etc.
Hence A→R2 also holds.
Summary:
Number per
One Multiple
table
View Serializability considers the overall effect on data values and final
reads/writes. Two schedules are view-equivalent if:
Lock-Based Protocol:
Transactions acquire locks (shared for reading, exclusive for writing). Locks
serialize conflicting operations. Strict two-phase locking (2PL) ensures
serializability and avoids some anomalies by acquiring all locks before releasing
any.
Timestamp-Based Protocol:
Each transaction gets a unique timestamp. Operations are ordered by
timestamp. Transactions with older timestamps have priority; conflicting
operations may abort younger transactions. No locks are used.
Validation-Based Protocol:
Transactions execute without restrictions but are validated at commit time.
Validation checks if the transaction conflicts with others. If conflict detected,
transaction aborts. It avoids lock overhead but can lead to aborts.
Part-B
Certainly! Here are detailed 300-word answers for Part-B DBMS questions 1 to
5:
Q1. Relational Algebra Expression for Sum of Salaries of All Employees
Given two relations:
Employee(Name, salary, dept_no)
Department(dept_no, deptname, address)
Relational algebra is a procedural query language used to manipulate and
retrieve data from relations. However, classical relational algebra does not have
built-in aggregate functions like SUM. To compute the sum of salaries, an
extended relational algebra with aggregation is needed.
To find the total sum of salaries of all employees:
γ_SUM(salary)(Employee)
Where:
γ is the grouping and aggregation operator
SUM(salary) computes the sum of the salary attribute from all tuples in
Employee
If aggregation by department is needed, the expression becomes:
γ_dept_no; SUM(salary)(Employee)
This groups employees by their department number and computes total salary
per department.
Without aggregation, pure relational algebra cannot directly express sum
operations, but practical DBMSs support aggregate functions in SQL and
extended algebra.
This expression helps managers understand payroll expenses overall or by
department.
FROM Employee
GROUP BY dept_no;
Explanation:
The GROUP BY dept_no clause groups employees by their department.
Q3. SQL Query to Get Employee Name with Highest Salary in Each
Department
SELECT E1.Name, E1.dept_no, E1.salary
FROM Employee E1
WHERE E1.salary = (
SELECT MAX(E2.salary)
FROM Employee E2
Explanation:
This handles ties where multiple employees have the highest salary.
T2 checks balance of A.
If T2 reads A’s balance before T1 commits, it may see inconsistent data.
Two types:
Conflict Serializability: Based on conflicting operations (read-write,
write-read).
View Serializability: Based on data read and final outputs.
Serializability is essential to avoid concurrency anomalies and ensure
correctness in multi-user environments.
Q6. Why Is a Transaction Required to Be Atomic? Explain Using Suitable
Example
Atomicity is a fundamental property of transactions in DBMS, meaning a
transaction is an indivisible unit of work that either completes entirely or does
not happen at all. This property ensures data integrity even in cases of system
failures, power outages, or errors during execution.
When a transaction is executed, it may consist of multiple operations like
reading, writing, updating data. Atomicity guarantees that if any operation
within the transaction fails, all the previously performed operations are undone
(rolled back) to maintain the database’s consistency.
Example: Consider a banking application where a transaction transfers $500
from Account A to Account B. The steps include:
Q10. Explain Candidate Key, Super Key, Foreign Key, Alternate Key, Composite
Key, and Artificial Key with Examples
Candidate Key: A minimal set of attributes that uniquely identify tuples
in a relation. There can be multiple candidate keys.
Example: In Employee(Name, EmpID, Email), EmpID and Email can both
be candidate keys.
Super Key: Any set of attributes that uniquely identifies a tuple, not
necessarily minimal.
Example: (EmpID, Name) is a super key because EmpID alone is a
candidate key.
Primary Key: The candidate key chosen by the database designer to
uniquely identify tuples.
Example: EmpID chosen as the primary key.
Foreign Key: An attribute (or set) in one relation that refers to the
primary key in another relation, used to maintain referential integrity.
Example: Dept_no in Employee references Dept_no in Department.
Alternate Key: Candidate keys not selected as primary key.
Example: Email, if not chosen as primary key, is an alternate key.
Composite Key: A key composed of two or more attributes to uniquely
identify a tuple.
Example: In Enrollment(StudentID, CourseID), both together uniquely
identify a record.
Artificial (Surrogate) Key: A system-generated key with no real-world
meaning, used for simplicity or performance.
Example: Auto-incremented ID numbers.
Each key type serves specific roles in ensuring uniqueness, establishing
relationships, and maintaining integrity within the database.
Part-C
Q1. What is Normalization? Explain All Types of Normal Forms with Example
Normalization is a fundamental database design process that organizes data to
reduce redundancy and dependency by dividing large tables into smaller
related tables. It improves data integrity and minimizes anomalies during data
operations like insert, update, or delete.
Types of Decomposition:
1. Lossless Decomposition:
A decomposition is lossless if the original relation can be perfectly
reconstructed by joining the decomposed relations. This prevents loss of
information.
Example:
Relation R(A, B, C) decomposed into R1(A, B) and R2(A, C) is lossless if
attribute A is a key. The join of R1 and R2 on A returns the original
relation without data loss.
2. Dependency Preserving Decomposition:
This ensures that all functional dependencies in the original relation can
be enforced in the decomposed relations without needing to join them.
This makes enforcement of constraints efficient.
Example:
If the original set of dependencies F can be split so that each FD is in one
of the decomposed relations, then the decomposition preserves
dependencies.
Decomposition helps eliminate redundancy, avoid anomalies, and make
databases easier to maintain. However, sometimes trade-offs exist between
lossless join and dependency preservation, so database designers must balance
these factors.
Dynamic SQL provides more flexibility but can be more complex to manage.
Part-B questions:
(b) Explain GRANT and REVOKE command with syntax and example.
GRANT: Used to give privileges to users on database objects such as
tables, views, etc. It controls who can perform operations like SELECT,
INSERT, UPDATE, DELETE.
Syntax:
GRANT privilege ON object TO user;
Example:
GRANT SELECT, INSERT ON Employee TO user1;
This allows user1 to read and insert records into the Employee table.
REVOKE: Used to withdraw previously granted privileges.
Syntax:
REVOKE privilege ON object FROM user;
Example:
REVOKE INSERT ON Employee FROM user1;
This removes insert permission from user1 on the Employee table.
Together, these commands enforce security by controlling user permissions in
the database.
Example:
(b) Write and explain syntax for creating and dropping synonyms with
example.
CREATE SYNONYM: Creates an alias for a database object, allowing
simpler or alternative naming.
Syntax:
CREATE SYNONYM synonym_name FOR object_name;
Example:
CREATE SYNONYM emp_syn FOR Employee;
Here, emp_syn is a synonym for the Employee table.
DROP SYNONYM: Removes the synonym from the database.
Syntax:
DROP SYNONYM synonym_name;
Example:
DROP SYNONYM emp_syn;
Synonyms simplify SQL commands by providing short or more meaningful
object references, especially useful in large or complex databases.
SELECT ename FROM EMP WHERE ename LIKE 'S%' AND deptno = 1002;
Advantages:
1. Eliminates Data Anomalies: Insert, update, and delete anomalies are
minimized.
2. Improves Data Integrity: Ensures consistency by removing redundant
data.
3. Efficient Storage: Reduces data duplication, saving storage space.
Q1. What are views? Explain how views are different from tables.
Views are virtual tables in a database that are defined by a SQL query. Unlike
regular tables, views do not store data physically; they dynamically display
data retrieved from one or more underlying base tables whenever accessed.
Views provide a way to present specific data subsets, filter rows, combine
columns from multiple tables, or hide complexity from users.
Key Characteristics of Views:
(b) What is data independence? Explain the difference between physical and
logical data independence.
Data Independence is the ability to change the schema at one level of a
database system without affecting the schema or applications at higher
levels. It is crucial for database evolution and maintenance.
Physical Data Independence:
Refers to the capacity to change physical storage details (e.g., indexing
methods, file organization) without affecting the conceptual schema or
user applications. For example, switching from one storage device to
another or reorganizing files does not require changes in applications.
Logical Data Independence:
Refers to the ability to change the conceptual schema without altering
external schemas or application programs. For example, adding new
fields or tables, changing relationships, or deleting attributes at the
conceptual level can be done without modifying applications.
Logical data independence is more difficult to achieve than physical because
applications often depend on the logical structure of data. Both forms of
independence improve database flexibility and reduce maintenance costs.
Types of Relationships:
1. One-to-One (1:1):
Each entity in set A is related to at most one entity in set B, and vice
versa.
Example: Each person has one unique passport.
2. One-to-Many (1:N):
An entity in set A can be associated with multiple entities in set B, but
each entity in B relates to only one entity in A.
Example: One department has many employees.
3. Many-to-Many (M:N):
Entities in set A can relate to multiple entities in set B and vice versa.
Example: Students enroll in many courses; courses have many
students.
4. Unary Relationship:
An entity relates to itself.
Example: An employee supervises other employees.
Relationships help structure data and define constraints, essential for
meaningful database design.
Given:
FROM S, SP, P
WHERE S.S# = SP.S# AND SP.P# = P.P# AND P.COLOR = 'Red';
(ii) Get supplier names who do not supply part P2:
SELECT SNAME
FROM S
WHERE S# NOT IN (
SELECT S#
FROM SP
WHERE P# = 'P2'
);
Q5. Discuss two-phase locking protocol. Variations with merits and demerits.
Two-Phase Locking (2PL) is a concurrency control method ensuring
serializability of transactions by dividing execution into two distinct phases:
1. Growing Phase: Transactions acquire all required locks but do not
release any.
2. Shrinking Phase: Transactions release locks and cannot acquire new
locks.
This protocol prevents conflicting operations from interleaving, ensuring
correct execution order.
Variations:
Strict 2PL: All locks are held until the transaction commits or aborts.
This avoids cascading rollbacks and guarantees recoverability but
reduces concurrency.
Rigorous 2PL: Similar to Strict 2PL but holds both shared and exclusive
locks until commit, simplifying recovery further but further limiting
concurrency.
Basic 2PL: Locks can be released anytime after the growing phase but
before commit, allowing higher concurrency but risking cascading
rollbacks.
Merits:
If you want me to continue with more questions or add diagrams, just ask!
Here are 350-word answers on Deadlock Handling Techniques and Protocols
and Recovery Schemes in DBMS:
Types of Failures
Transaction Failure: Logical errors or system crashes.
These mechanisms ensure that DBMS maintains data integrity even during
unexpected failures or concurrency issues.
Here is a 350-word detailed answer covering the meaning of concurrency,
deadlock, and their types:
Meaning of Deadlock:
A deadlock is a situation where two or more transactions are waiting for each
other to release locks, and none of them can proceed. It is a serious problem
in concurrent transaction processing and can lead to system stalling.
Example:
Transaction T1 locks resource A and waits for B, while T2 locks B and waits for
A. Neither can proceed, leading to a deadlock.
Triggers:
Triggers are automatic actions executed in response to specific events on a
table.
Example:
CREATE TRIGGER log_update AFTER UPDATE ON Employee FOR EACH ROW
INSERT INTO log_table VALUES (...);