0% found this document useful (0 votes)
11 views

Dbms Imp Quest Ans

Uploaded by

Raghu S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Dbms Imp Quest Ans

Uploaded by

Raghu S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1 ) Explanation of Normal Forms with Examples

First Normal Form (1NF)


Definition: A relation is in the first normal form if it contains only atomic
(indivisible) values; that is, it does not contain sets, arrays, or any other
complex data structures.
Example: Consider a table Students:

StudentID Name Courses

1 Alice Math, English

2 Bob Science, History

This table is not in 1NF because the Courses column contains a list of courses,
which is not atomic.
To convert it into 1NF, we need to ensure each field contains only atomic
values:

StudentID Name Course

1 Alice Math

1 Alice English

2 Bob Science

2 Bob History

Second Normal Form (2NF)


Definition: A relation is in the second normal form if it is in 1NF and all non-
prime attributes are fully functionally dependent on the primary key.
Example: Consider a table Orders:

OrderID ProductID ProductName Quantity UnitPrice

1 101 Widget 4 25.00

2 102 Gizmo 2 15.00

This table is not in 2NF because ProductName and UnitPrice depend only on
ProductID, not on the entire primary key OrderID and ProductID.
To convert it into 2NF, we split the table into two:
• Orders:

OrderID ProductID Quantity

1 101 4

2 102 2

• Products:

ProductID ProductName UnitPrice

101 Widget 25.00

102 Gizmo 15.00

Third Normal Form (3NF)


Definition: A relation is in the third normal form if it is in 2NF and all the
attributes are functionally dependent only on the primary key, and not on any
other non-prime attribute (i.e., no transitive dependency).
Example: Consider a table Employees:

EmpID EmpName DeptID DeptName

1 John 10 Sales

2 Jane 20 HR

This table is not in 3NF because DeptName depends on DeptID, which in turn
depends on EmpID.
To convert it into 3NF, we split the table into two:
• Employees:

EmpID EmpName DeptID

1 John 10

2 Jane 20

• Departments:
DeptID DeptName

10 Sales

20 HR

Citations
This explanation is based on the provided material from the uploaded PDF
files, specifically covering the sections on normalization and the definitions of
1NF, 2NF, and 3NF(Module 4 VC).

2) 2. Retrieve the name and address of all employees who work for the
‘Research’ department
sql
Copy code
SELECT E.name, E.address
FROM EMPLOYEE E, DEPARTMENT D
WHERE E.department_id = D.id AND D.name = 'Research';
3. List all project numbers for projects that involve an employee whose last
name is ‘Smith’
sql
Copy code
SELECT DISTINCT P.project_number
FROM PROJECT P, WORKS_ON W, EMPLOYEE E
WHERE P.project_number = W.project_number AND W.ssn = E.ssn AND
E.lname = 'Smith';
4. List the names of managers who have at least one dependent
sql
Copy code
SELECT E.Fname, E.Lname
FROM EMPLOYEE E
WHERE EXISTS (SELECT * FROM DEPENDENT D WHERE E.Ssn = D.Essn)
AND EXISTS (SELECT * FROM DEPARTMENT DEPT WHERE E.Ssn =
DEPT.Mgr_ssn);
5. Find the sum of the salaries of all employees, the maximum salary, the
minimum salary, and the average salary
sql
Copy code
SELECT SUM(Salary), MAX(Salary), MIN(Salary), AVG(Salary)
FROM EMPLOYEE;
6. For each project, retrieve the project number, the project name, and the
number of employees who work on that project
sql
Copy code
SELECT P.project_number, P.project_name, COUNT(*)
FROM PROJECT P, WORKS_ON W
WHERE P.project_number = W.project_number
GROUP BY P.project_number, P.project_name;
7. List the names of all employees who have two or more dependents
sql
Copy code
SELECT E.Lname, E.Fname
FROM EMPLOYEE E
WHERE (SELECT COUNT(*) FROM DEPENDENT D WHERE E.Ssn = D.Essn) >= 2;
8. Retrieve the names and addresses of employees who work on at least one
project located in ‘Houston’
sql
Copy code
SELECT DISTINCT E.name, E.address
FROM EMPLOYEE E, WORKS_ON W, PROJECT P
WHERE E.ssn = W.ssn AND W.project_number = P.project_number AND
P.location = 'Houston';
9. For each department, retrieve the department number, the number of
employees, and their average salary
sql
Copy code
SELECT D.department_number, COUNT(*), AVG(E.salary)
FROM DEPARTMENT D, EMPLOYEE E
WHERE D.department_number = E.department_number
GROUP BY D.department_number;
10. Retrieve the names of employees who do not have any dependents
sql
Copy code
SELECT E.name
FROM EMPLOYEE E
WHERE NOT EXISTS (SELECT * FROM DEPENDENT D WHERE E.ssn = D.ssn);
11. Retrieve the department names and the number of employees working in
each department
sql
Copy code
SELECT D.department_name, COUNT(*)
FROM DEPARTMENT D, EMPLOYEE E
WHERE D.department_id = E.department_id
GROUP BY D.department_name;
12. Retrieve the names of employees who are directly supervised by ‘John
Smith’
sql
Copy code
SELECT E.name
FROM EMPLOYEE E, EMPLOYEE S
WHERE E.supervisor_ssn = S.ssn AND S.name = 'John Smith';
13. Retrieve the names of employees who work on all projects that ‘John
Smith’ works on
sql
Copy code
SELECT DISTINCT E.name
FROM EMPLOYEE E
WHERE NOT EXISTS (
SELECT P.project_number
FROM PROJECT P, WORKS_ON W, EMPLOYEE S
WHERE P.project_number = W.project_number AND W.ssn = S.ssn AND
S.name = 'John Smith'
EXCEPT
SELECT P.project_number
FROM PROJECT P, WORKS_ON W
WHERE P.project_number = W.project_number AND W.ssn = E.ssn
);
14. For each project, retrieve the project number, the project name, and the
total hours worked on that project
sql
Copy code
SELECT P.project_number, P.project_name, SUM(W.hours)
FROM PROJECT P, WORKS_ON W
WHERE P.project_number = W.project_number
GROUP BY P.project_number, P.project_name;
15. Retrieve the names of employees who have no supervisors
sql
Copy code
SELECT E.name
FROM EMPLOYEE E
WHERE E.supervisor_ssn IS NULL;
16. Retrieve the names of employees who work in the department that has
the employee with the highest salary
sql
Copy code
SELECT E.name
FROM EMPLOYEE E, DEPARTMENT D
WHERE E.department_id = D.department_id
AND D.department_id = (
SELECT E1.department_id
FROM EMPLOYEE E1
ORDER BY E1.salary DESC
LIMIT 1
);
17. Retrieve the names of employees who have the same job title as their
supervisor
sql
Copy code
SELECT E.name
FROM EMPLOYEE E, EMPLOYEE S
WHERE E.supervisor_ssn = S.ssn AND E.job_title = S.job_title;
18. Retrieve the names of employees who have changed their job title
sql
Copy code
SELECT DISTINCT E.name
FROM EMPLOYEE_HISTORY EH, EMPLOYEE E
WHERE EH.ssn = E.ssn AND EH.job_title <> E.current_job_title;
19. Retrieve the names of employees who work on more than one project
sql
Copy code
SELECT E.name
FROM EMPLOYEE E, WORKS_ON W
WHERE E.ssn = W.ssn
GROUP BY E.name
HAVING COUNT(W.project_number) > 1;
20. Retrieve the name of the department with the highest total salary
sql
Copy code
SELECT D.department_name
FROM DEPARTMENT D, EMPLOYEE E
WHERE D.department_id = E.department_id
GROUP BY D.department_name
ORDER BY SUM(E.salary) DESC
LIMIT 1;
These answers are based on the SQL syntax and examples provided in the
documents you uploaded

5) ACID Properties of a Transaction and System Log


ACID Properties:
1. Atomicity: Ensures that all operations of a transaction are completed; if
not, the transaction is aborted. For example, in a bank transfer, either
both the debit and credit operations occur, or neither does.
2. Consistency: Ensures that a transaction transforms the database from
one consistent state to another. For example, if a transaction deducts
money from one account, it must add it to another.
3. Isolation: Ensures that intermediate transaction states are invisible to
other transactions. For example, while one transaction updates a
balance, another transaction cannot read the intermediate value.
4. Durability: Ensures that once a transaction is committed, it remains so,
even in the event of a system failure. For example, once a bank transfer
is complete, the changes are permanent.
System Log: A system log is a record of all transactions that helps in recovering
the database to a consistent state in case of a failure. It records transaction
start, commit, and rollback events.
6. Why Concurrency Control Is Needed? Explain with an example
Concurrency Control: Concurrency control is needed to ensure the consistency
and isolation properties of transactions in a multi-user environment. It
prevents problems like lost updates, temporary inconsistency, and
uncommitted data.
Example: Consider two transactions T1 and T2:
• T1: Reads a balance of $1000, adds $100, and writes back $1100.
• T2: Reads the same balance, subtracts $200, and writes back $800.
Without concurrency control, if T1 and T2 execute simultaneously, the final
balance could be incorrect. Concurrency control mechanisms like locking
ensure transactions are isolated, preventing such issues.
7. Demonstrate working of Assertion & Triggers in database? Explain with an
example
Assertions: Assertions are constraints that apply to multiple tables to ensure
data integrity.
Example:
sql
Copy code
CREATE ASSERTION salary_check
CHECK (NOT EXISTS (SELECT * FROM EMPLOYEE WHERE Salary > 50000 AND
Department = 'HR'));
This ensures no employee in HR has a salary over $50,000.
Triggers: Triggers automatically perform specified actions in response to
certain events on a table.
Example:
sql
Copy code
CREATE TRIGGER update_salary
AFTER UPDATE ON EMPLOYEE
FOR EACH ROW
WHEN (NEW.Salary > 50000)
BEGIN
UPDATE SALARY_AUDIT SET OverLimit = 'Yes' WHERE EmployeeID =
NEW.EmployeeID;
END;
This trigger updates a record in the SALARY_AUDIT table if an employee’s
salary exceeds $50,000.
8. Define Functional Dependency. With example explain different types of
functional dependency
Functional Dependency: A functional dependency occurs when one attribute
uniquely determines another attribute in a relation.
Example: In a relation R(A, B), B is functionally dependent on A (A -> B) if each
value of A is associated with exactly one value of B.
Types:
1. Trivial Functional Dependency: When an attribute is dependent on a
subset of itself. Example: A -> A.
2. Non-Trivial Functional Dependency: When an attribute is dependent on
another attribute. Example: A -> B.
3. Multivalued Dependency: When one attribute determines a set of
values for another. Example: A ->> B.
4. Transitive Dependency: When A -> B and B -> C, then A -> C. Example:
StudentID -> DepartmentID, DepartmentID -> HOD, thus StudentID ->
HOD.

10) Explain the advantages and problems in concurrent processing


Advantages:
1. Resource Utilization: Concurrent processing enables better utilization of
system resources such as CPU, memory, and I/O devices. When one
process is waiting for I/O operations, another can utilize the CPU, thus
ensuring that resources are not left idle.
2. Improved Throughput: By allowing multiple transactions to be
processed simultaneously, concurrent processing increases the overall
throughput of the system. This is particularly beneficial in environments
with high transaction volumes, such as banking and airline reservations.
3. Reduced Waiting Time: Users experience reduced waiting times as their
transactions do not need to wait for previous transactions to complete.
This is especially important in real-time systems where prompt
responses are critical.
4. Enhanced Performance: Concurrent processing can significantly
enhance system performance by dividing tasks into smaller, manageable
units that can be executed in parallel. This parallelism can lead to faster
completion of complex tasks.
Problems:
1. Concurrency Control: One of the primary challenges in concurrent
processing is ensuring that concurrent transactions do not interfere with
each other. Without proper concurrency control mechanisms, issues like
lost updates, temporary updates (dirty reads), incorrect summaries, and
unrepeatable reads can occur, leading to data inconsistencies.
2. Deadlocks: Deadlocks occur when two or more transactions are waiting
indefinitely for resources held by each other. This situation can halt the
progress of all involved transactions, necessitating deadlock detection
and resolution mechanisms.
3. Isolation Levels: Ensuring the isolation of transactions while allowing
concurrency is complex. Different isolation levels (e.g., read
uncommitted, read committed, repeatable read, and serializable) offer
trade-offs between performance and the likelihood of encountering
concurrency problems.
4. Complexity of Implementation: Implementing effective concurrency
control mechanisms, such as locking protocols, timestamp ordering, and
multiversion concurrency control, adds complexity to the database
management system. These mechanisms must be carefully designed and
optimized to balance performance and consistency requirements.
In summary, while concurrent processing offers significant advantages in
terms of resource utilization, throughput, and performance, it also
introduces challenges related to concurrency control, deadlocks, and
system complexity. Effective management of these challenges is crucial
for maintaining data integrity and ensuring smooth system operation

11) Desirable Properties of Transactions in RDBMS


In an RDBMS, transactions must possess the following ACID properties to
ensure data integrity and consistency:
1. Atomicity: Ensures that all operations within a transaction are
completed successfully. If any operation fails, the entire transaction is
rolled back. For example, in a bank transfer, both debit and credit
operations must complete; otherwise, neither occurs.
2. Consistency: Ensures that a transaction transforms the database from
one consistent state to another. For instance, if a transaction violates a
database constraint, it will be rolled back to maintain consistency.
3. Isolation: Ensures that the operations of a transaction are isolated from
those of other transactions. This prevents concurrent transactions from
interfering with each other. For example, while one transaction is
updating a record, another transaction cannot access the intermediate
state of that record.
4. Durability: Ensures that once a transaction is committed, its changes are
permanent, even in the event of a system failure. This is achieved
through techniques like write-ahead logging and checkpointing.
These properties are crucial for reliable transaction management in RDBMS,
ensuring that the database remains accurate and consistent despite
concurrent access and system failures.

12. Explain with the neat diagram the state transition diagram of a
Transaction
Transaction States and Additional Operations
A transaction is an atomic unit of work that should either be completed in its
entirety or
not done at all. For recovery purposes, the system keeps track of start of a
transaction,
termination, commit or aborts.
BEGIN_TRANSACTION: marks the beginning of transaction execution
READ or WRITE: specify read or write operations on the database items that
are
executed as part of a transaction
END_TRANSACTION: specifies that READ and WRITE transaction operations
have
ended and marks the end of transaction execution
COMMIT_TRANSACTION: signals a successful end of the transaction so that
any
changes (updates) executed by the transaction can be safely committed to the
database and will not be undone
ROLLBACK: signals that the transaction has ended unsuccessfully, so that any
changes or effects that the transaction may have applied to the database must
be
undone
A transaction goes into active state immediately after it starts execution and
can
execute read and write operations.
When the transaction ends it moves to partially committed state.
At this end additional checks are done to see if the transaction can be
committed or not.
If these checks are successful the transaction is said to have reached commit
point and
enters committed state. All the changes are recorded permanently in the db.
A transaction can go to the failed state if one of the checks fails or if the
transaction is
aborted during its active state. The transaction may then have to be rolled
back to undo
the effect of its write operation.
Terminated state corresponds to the transaction leaving the system. All the
information
about the transaction is removed from system tables.

Two-Phase Locking Techniques for Concurrency Control


The concept of locking data items is one of the main techniques used for
controlling the
concurrent execution of transactions.
A lock is a variable associated with a data item in the database. Generally there
is a lock
for each data item in the database.
A lock describes the status of the data item with respect to possible operations
that can be
applied to that item.
It is used for synchronizing the access by concurrent transactions to the
database items.
A transaction locks an object before using it
When an object is locked by another transaction, the requesting transaction
must wait

You might also like