DBMS QB Templete - 2024 - Answers
DBMS QB Templete - 2024 - Answers
PART B
A Database Management System (DBMS) is software that enables users to store, retrieve,
manage, and manipulate data efficiently. It ensures data security, integrity, and consistency
while providing tools for querying and updating databases.
1. Data Redundancy: Multiple copies of the same data can exist, leading to
inconsistencies.
2. Data Inconsistency: Changes in one file may not be reflected in others, causing
mismatched data.
3. Difficulty in Accessing Data: Queries are hard to construct and often require custom
code.
4. Limited Data Sharing: Sharing data between programs is complex.
5. Security Issues: File systems offer minimal security features.
6. Concurrency Control: Multiple users cannot access or update data simultaneously
without conflicts.
7. No Data Recovery Mechanism: No backup and recovery features to prevent data
loss.
8. Integrity Constraints: Hard to enforce rules for maintaining data integrity.
Write down the advantages of .
1. Simple Language: Easy to learn and use, with commands resembling English.
2. Standardized Language: ANSI and ISO standard language used globally.
3. Data Manipulation: Allows insertion, updating, and deletion of records efficiently.
4. Query Flexibility: Enables complex queries using JOIN, UNION, and subqueries.
5. Scalability: Suitable for handling large datasets.
6. Security Features: Provides permissions and roles for access control.
7. Portability: Works with multiple databases like My, Oracle, Server, etc.
8. Integration: Supports integration with other programming languages like Python,
Java, and C++.
9. Data Definition and Control: Allows schema creation, modification, and
enforcement of constraints.
10. Transaction Control: Manages transactions using commands like COMMIT and
ROLLBACK.
Query Processor:
A Query Processor in DBMS interprets and executes queries. It translates user requests into
database commands for data retrieval or modification.
Key Components:
1. Query Parser: Checks the query syntax and verifies its correctness.
2. Query Optimizer: Optimizes query execution plans to minimize time and resource
usage.
3. Query Executor: Executes the optimized query to retrieve or modify data.
4. DDL Interpreter: Processes schema definitions and structure modifications.
Data Independence refers to the ability to modify a database schema without affecting the
application programs that use the data. It simplifies database maintenance and promotes
flexibility.
1. Redundancy:
o Problem: Redundancy occurs when the same information is stored in multiple
places, leading to data inconsistency.
o Example: If an employee's department information is stored both in the Employee
and Department entities, changes in one might not reflect in the other.
o Solution: Normalize the data by separating it into distinct entities and defining
relationships properly.
2. Weak Entities:
o Problem: Weak entities cannot exist without a strong entity, and designing
relationships between them requires identifying relationships and foreign keys.
o Example: A Dependent entity (child) depends on a Parent entity.
o Solution: Assign a discriminator (partial key) and link it to the primary key of the
strong entity.
1. E-R Model:
o The Entity-Relationship (E-R) Model represents data using entities, attributes, and
relationships.
o It is a conceptual design tool used to visualize database structure before
implementation.
o Components:
Entities: Objects (e.g., Student, Teacher).
Attributes: Properties of entities (e.g., Name, Age).
Relationships: Associations between entities (e.g., Teaches).
2. Relational Model:
o The Relational Model represents data in tables (relations) consisting of rows
(tuples) and columns (attributes).
o It focuses on data storage and retrieval using and supports normalization to
eliminate redundancy.
o Components:
Relation/Table: Stores data.
Primary Key: Ensures unique identification of rows.
Foreign Key: Establishes relationships between tables.
Explain the different types of Keys in DBMS.
1. Primary Key:
o A unique identifier for a record in a table (e.g., Student_ID).
2. Candidate Key:
o A set of attributes that can uniquely identify a record. One candidate key is chosen
as the primary key.
3. Super Key:
o A set of attributes that can uniquely identify a record, but may include extra
attributes (e.g., {Student_ID, Name}).
4. Foreign Key:
o An attribute in one table that refers to the primary key of another table, establishing
a relationship.
5. Alternate Key:
o Candidate keys that are not selected as the primary key.
6. Composite Key:
o A key formed by combining two or more attributes to uniquely identify records.
7. Unique Key:
o Ensures all values in a column are distinct but allows NULL values.
1. Entities to Tables:
o Each entity in the E-R diagram becomes a table.
o Attributes become columns, and the primary key is selected.
2. Relationships to Foreign Keys:
o Relationships are converted into foreign keys to link tables.
o For 1:1 relationships, add the primary key of one table as a foreign key in the other.
o For 1:N relationships, add the primary key of the '1' side as a foreign key in the 'N'
side.
o For M:N relationships, create a new table with both primary keys as composite
keys.
3. Weak Entities to Tables:
o Include a foreign key referencing the strong entity and a discriminator attribute.
Mapping Cardinality:
Mapping Cardinality defines the number of associations between entities in a relationship.
It specifies how many instances of one entity can be related to instances of another entity.
1. One-to-One (1:1):
o Example: Husband - Wife (Each husband has one wife, and vice versa).
2. One-to-Many (1:N):
o Example: Department - Employee (One department has many employees, but an
employee belongs to one department).
3. Many-to-One (M:1):
o Example: Student - Advisor (Many students have one advisor).
4. Many-to-Many (M:N):
o Example: Student - Course (Many students enroll in many courses).
List out the operations of the relational algebra with suitable example
(Any five)
1. Selection (σ):
o Filters rows based on a condition.
o Example:
σ(Dept = 'IT') (Employee) – Selects employees from the IT department.
2. Projection (π):
o Displays specific columns (attributes).
o Example:
π(Name, Salary) (Employee) – Displays only the Name and Salary columns.
3. Union (∪):
o Combines rows from two relations (tables) with no duplicates.
o Example:
Employee ∪ Manager – Combines rows from Employee and Manager tables.
4. Intersection (∩):
o Returns rows that are common between two relations.
o Example:
Employee ∩ Manager – Finds common rows in both tables.
5. Join (⨝):
o Combines rows from two relations based on a common attribute.
o Example:
Employee ⨝ Dept (DeptNo) – Joins Employee and Dept on the DeptNo column.
1. List all the employees whose name starts with the letter ‘S’:
1. Subquery:
o A query inside another query, executed first, and its result is used in the outer
query.
o Example:
SELECT Name FROM Employee WHERE Salary > (SELECT AVG(Salary) FROM Employee);
The inner query calculates the average salary, and the outer query fetches employees with salaries
above average.
Nested Query:
SELECT Name FROM Employee WHERE Dept = (SELECT Dept FROM Employee WHERE Name =
'John');
The inner query fetches John’s department, and the outer query lists employees in the same
department.
Select (σ):
Project (π):
1. Create Table:
2. Insert Data:
3. Select Data:
5. Drop Table:
1. Reflexivity:
o If Y ⊆ X, then X → Y (Subset dependency).
o Example: {A, B} → A.
2. Augmentation:
o If X → Y, then XZ → YZ (Adding attributes preserves dependency).
o Example: A → B implies AC → BC.
3. Transitivity:
o If X → Y and Y → Z, then X → Z.
o Example: A → B and B → C implies A → C.
4. Union:
o If X → Y and X → Z, then X → YZ (Combine dependencies).
o Example: A → B and A → C implies A → {B, C}.
5. Decomposition:
o If X → YZ, then X → Y and X → Z.
o Example: A → {B, C} implies A → B and A → C.
6. Pseudotransitivity:
o If X → Y and WY → Z, then WX → Z.
o Example: A → B and CB → D implies CA → D.
1. Information Rule:
o All data must be stored in table format (rows and columns).
2. Guaranteed Access Rule:
o Each data item must be accessible through a combination of table name, primary
key, and column name.
3. Systematic Treatment of NULL Values:
o NULL values must be treated uniformly to represent missing or inapplicable
information.
4. Active Online Catalog:
o Metadata should be stored in the database and accessible using .
5. Comprehensive Data Sublanguage Rule:
o The database must support a language like for data definition, manipulation, and
transaction management.
Start
Active
↙ ↘
Partially Failed
Committed ↓
↓ Aborted
Committed ↑
Rollback
Active:
Partially Committed:
Committed:
Failed:
Transaction violates constraints or encounters errors.
Aborted:
Indexing in DBMS:
Types of Indexing:
1. Primary Index:
o Built on the primary key of the table.
o Example: Index on Student_ID in the Student table.
2. Secondary Index:
o Built on non-key attributes to speed up queries.
o Example: Index on Student_Name for searching names quickly.
3. Clustered Index:
o Rows are physically ordered based on the index.
o Example: Index on Employee_ID, where records are stored in sorted order.
4. Non-clustered Index:
o Creates a separate structure that maps index keys to row pointers.
o Example: Index on City in a table where data is unordered.
5. Unique Index:
o Ensures that indexed values are unique in the table.
o Example: Index on Email_ID in a user table.
6. Bitmap Index:
o Efficient for columns with low cardinality (few distinct values).
o Example: Index on Gender or Status columns.
Serializability:
1. Conflict Serializability:
o Ensures that transactions can be rearranged to form a serial schedule by swapping
non-conflicting operations.
o Conflicting Operations: Two operations conflict if:
1. They operate on the same data item.
2. At least one operation is a write.
o Example: T1: Read(A), Write(A) and T2: Write(A) conflict, but T1: Read(A) and T2:
Read(A) do not.
2. View Serializability:
o Transactions produce the same result as a serial execution, even if their operations
are interleaved.
o It is less restrictive than conflict serializability but harder to test.
Types of Recoverability:
1. Recoverable Schedule:
o A schedule where transactions commit only after all transactions whose changes
they depend on have committed.
o Example: T1 writes data; T2 reads it. T2 should commit only after T1 commits.
2. Cascadeless Schedule:
o Prevents cascading rollbacks by ensuring that a transaction reads only committed
data.
o Example: If T1 fails, T2 (which depends on T1) does not need to roll back because it
didn’t read uncommitted data.
3. Strict Schedule:
o Ensures no changes are made until transactions commit, maintaining a strong
consistency guarantee.
o Example: Transactions can neither read nor write uncommitted data.
4. Rigorous Schedule:
o Stronger than strict schedules, it prevents reading and writing of data until a
transaction has fully committed.
Triggers in DBMS:
Triggers are predefined procedures or rules that are automatically executed in response to
specific events (INSERT, UPDATE, DELETE) on a table or view.
Syntax Example:
BEGIN
END IF;
END;
Benefits of Triggers:
PART C
A view in DBMS is a virtual table based on the result of a query. It does not store data itself
but provides a customized perspective of the data stored in the database.
1. Simple View
Definition: A view that is created from a single table without any aggregation or
grouping.
Example:
2. Complex View
Definition: A view created using multiple tables, joins, or with aggregation functions.
Example:
CREATE VIEW DeptSalaryView AS
SELECT Department, AVG(Salary) AS AvgSalary
FROM Employee
GROUP BY Department;
Use: Shows aggregated data and combines information from multiple tables.
3. Materialized View
Definition: Unlike regular views, it stores the result of the query physically and
refreshes periodically.
Example:
Common Commands:
Common Commands:
INSERT INTO Students (StudentID, Name, Age) VALUES (1, 'John', 18);
Conclusion:
Views simplify data access and improve security by limiting data exposure.
DDL commands define and manage database structures, while DML commands
handle data manipulation within those structures.
Mastering these commands is fundamental to working with relational databases.
Relationships:
1. Aggregation:
o Definition: It is a higher-level relationship that represents a relationship
between relationships.
o Example: In the Health Care System, an Appointment involves both Patient
and Doctor, and this relationship can be associated with Bill.
o Diagram Representation: A diamond symbol representing the association
between entities.
2. Generalization:
o Definition: Process of extracting shared characteristics from two or more
entities and creating a higher-level entity.
o Example: Entities Surgeon and Physician can be generalized into a single
entity Doctor.
o Diagram Representation: An arrow pointing from child entities to the parent
entity.
3. Specialization:
o Definition: Opposite of generalization, where a higher-level entity is divided
into sub-entities based on specific attributes.
o Example: Entity Doctor can be specialized into Surgeon and Physician.
o Diagram Representation: An arrow pointing from the parent entity to child
entities.
Design Constraints:
What is Join and Explain in detail about various types of Joins with
suitable examples.
JOIN
A JOIN is used to combine rows from two or more tables based on a related column
between them. It allows querying data from multiple tables as if they were a single table.
Types of Joins
1. INNER JOIN
o Returns rows that have matching values in both tables.
o Syntax:
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
o Example:
SELECT columns
FROM table1
LEFT JOIN table2
ON table1.column = table2.column;
o Example:
SELECT columns
FROM table1
RIGHT JOIN table2
ON table1.column = table2.column;
o Example:
SELECT columns
FROM table1
FULL JOIN table2
ON table1.column = table2.column;
o Example:
o Output: Includes all employees and departments, showing NULL wherever no match
is found.
5. CROSS JOIN
o Returns the Cartesian product of both tables, combining each row of the first table
with every row of the second table.
o Syntax:
SELECT columns
FROM table1
CROSS JOIN table2;
o Example:
SELECT Employees.Name, Departments.DepartmentName
FROM Employees
CROSS JOIN Departments;
o Example:
Relational Algebra
Relational Algebra is a procedural query language used to manipulate and retrieve data
stored in relational databases. It provides a foundation for SQL queries.
R1 ⋃ R2
R1 ⋂ R2
R1 − R2
R1 × R2
R1 ⨝ R1.A = R2.B R2
1. Division (÷) – Finds rows in one relation that match all rows in another.
Example:
css
A ÷ B
o Used for queries like “Find students who have taken all courses.”
2. Aggregation Functions – Performs operations like SUM, AVG, MIN, MAX, etc.
Example:
γ Department (Employees)
Normalization is a process in database design that organizes data to reduce redundancy and improve
data integrity. It involves dividing a database into two or more tables and defining relationships
between the tables.
Rule: Eliminate duplicate columns and ensure each column contains atomic values (indivisible).
Example:
OrderIDCustomer Products
1NF Solution:
OrderIDCustomer Product
1 John Pen
1 John Notebook
2 Mary Pencil
2 Mary Eraser
Rule: Meet all 1NF requirements and ensure all non-key columns are fully dependent on the primary
key.
Example:
Orders Table:
OrderIDProduct
1 Pen
1 Notebook
Customers Table:
Customer Address
Rule: Meet all 2NF requirements and eliminate transitive dependency (no non-key column should
depend on another non-key column).
Example:
OrderIDCustomerID City State ZipCode
Orders Table:
OrderIDCustomerID ZipCode
1 101 10001
ZipCode Table:
DECLARE
num1 NUMBER := 10; -- Declaration
num2 NUMBER := 20;
sum NUMBER;
BEGIN
sum := num1 + num2; -- Execution
DBMS_OUTPUT.PUT_LINE('Sum = ' || sum); -- Output statement
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred'); -- Error handling
END;
/
Explanation:
Explain in detail about database security and its control measures are
used to provide security of data in databases
Database Security
Database security involves protecting the database from unauthorized access, misuse, and
malicious threats. It ensures confidentiality, integrity, and availability (CIA) of data.
Concurrency control ensures that multiple transactions can occur simultaneously without
causing inconsistencies. It prevents lost updates, dirty reads, and uncommitted data issues.
The 2PL protocol ensures serializability by dividing a transaction’s locking phase into two
parts:
1. Growing Phase:
o The transaction acquires locks as needed but cannot release any lock.
2. Shrinking Phase:
o The transaction releases locks but cannot acquire any new lock.
Rules:
Example of 2PL
Transactions:
Steps:
Advantages of 2PL:
Guarantees serializability.
Suitable for applications requiring strict consistency.
Disadvantages of 2PL: