DBMS Solved 2022
DBMS Solved 2022
2. Definition: Levels of data abstraction in a database management system (DBMS) are systematic layers
that conceal internal complexity from users, enabling simplified interaction and efficient use of stored
data.
o Describes how data is actually stored in the database (file structures, indexes, memory blocks).
o Defines what data is stored, how fields (attributes) relate, and the logical structure of tables and
relationships.
o Example: Payroll department views only salary-related columns; HR views contact information.
o DBMS manages mapping to ensure changes at one level (e.g., physical storage) do not affect other
levels (data independence).
7. Data Independence:
o The abstraction enables physical data independence (changes in storage should not affect logical
structure) and logical data independence (changes in logical schema do not alter external views).
8. Example Scenario:
o In a student database:
▪ View Level: Result view shows roll number and marks only.
9. Purpose:
o Abstraction shields users from complexity, improves usability, supports efficient query processing,
and enhances security.
10. Conclusion:
o A candidate key is a minimal set of one or more attributes that uniquely identify each tuple (row)
in a relation.
Every table can have multiple candidate keys.
o A primary key is a selected candidate key used to uniquely identify each record in a table; it does
not allow nulls or duplicate values.
o A foreign key is an attribute in one table that refers to the primary key of another table,
establishing referential integrity between related tables.
4. Schema: Person (driver_id, name, address, contactno) o Candidate Key: driver_id (uniquely identifies
5. Schema: Car (licence, model, year) o Candidate Key: licence (uniquely identifies each car) o Primary
6. Schema: Owns (driver_id, licence) o Candidate Key: Composite of (driver_id, licence) (uniquely
identifies each ownership record) o Primary Key: (driver_id, licence) o Foreign Key: driver_id
7. Illustration:
o Each Person may own multiple cars, each Car can be owned by multiple persons.
SPPU_TE_BE_COMP Click to join telegram
o Owns serves as a relationship table connecting Person and Car entities.
9. Mapping Cardinality: In Owns, both driver_id and licence together act as a composite primary key,
supporting manyto-many relationships.
10. Note: The composite key in Owns ensures that the same person can own multiple cars, and different
persons can own the same car (if allowed by scenario).
11. Conclusion: Candidate keys provide all possible unique identifiers, a primary key is selected for unique
identification, and a foreign key maintains links and referential integrity between related tables.
12. All answers strictly use official DBMS terminology per SPPU 2019 syllabus; mapping and identification
are technically accurate.
1. Storage Manager:
o Acts as the interface between the low-level data stored in the database and the application
programs or queries. o Responsible for efficient storing, retrieving, and updating data in the
physical storage.
SPPU_TE_BE_COMP Click to join telegram
o Maintains consistency and integrity by enforcing constraints and managing transaction logs. o
Manages space allocation on disk, data structures for files, and indexes to optimize access. o
▪ Buffer Manager: Handles caching of data between disk and main memory to reduce I/O
operations.
▪ Transaction Manager: Ensures atomicity, consistency, isolation, and durability (ACID) during
concurrent executions.
2. Query Processor:
o Interprets and executes user queries written in high-level languages like SQL. o Converts queries
o Components include:
▪ DDL Interpreter: Processes Data Definition Language statements and updates metadata.
▪ Embedded DML Pre-compiler: Handles DML statements embedded within application code.
▪ Query Optimizer: Improves query efficiency by selecting the best execution plan considering
indexes, join orders, and system resources.
o Ensures queries run efficiently and provide correct results by parsing, translating, optimizing, and
executing.
3. Summary:
o The Storage Manager handles physical data management and transaction safety.
o The Query Processor acts as the translator and optimizer of user queries for efficient execution.
These components together form the core of the DBMS, enabling reliable and efficient data management.
SPPU_TE_BE_COMP Click to join telegram
Q3) a) What is view and how to create it? Can you update
view? If yes, how? If not, why not? [5]
1. Definition of View:
o A view is a virtual table in a database derived from a query on one or more base tables. It does not
store data physically, but dynamically displays data generated from underlying tables.
o Example:
o Some views can be updated if the DBMS can map changes on the view back to the underlying base
tables unambiguously.
o Views without joins, aggregates, grouping, or computed columns are usually updatable.
o Use conventional DML statements (INSERT, UPDATE, DELETE) on the view as if it were a table.
Behind the scenes, DBMS translates these operations to base tables.
o Example:
o Views involving multiple base tables, joins, aggregate functions, GROUP BY, DISTINCT, or derived
columns are generally non-updatable because DBMS cannot deterministically map changes to base
tables.
o Updatable views allow direct data modification under certain conditions; otherwise, views are
read-only.
7. Conclusion:
o Views facilitate simplified data access and controlled updates when feasible but have inherent
limitations depending on their complexity.
o A stored procedure is a precompiled set of one or more SQL statements stored in the database
that can be executed repeatedly as a single unit. It encapsulates logic to perform specific tasks or
operations on the database.
2. Purpose:
EXEC ProcedureName;
5. Example:
SPPU_TE_BE_COMP Click to join telegram
CREATE PROCEDURE GetAllCustomers
AS
BEGIN
SELECT CustomerID, CustomerName, City FROM Customers;
END;
-- Calling procedure
EXEC GetAllCustomers;
This modular approach streamlines database operations and enhances maintainability of complex systems.
1. Definition: A trigger is a stored action executed automatically in response to DML events on a table; here,
a BEFORE UPDATE trigger will capture old values.
2. Assumptions: SQL dialect supports row-level triggers; an audit table exists to store old values.
4. Purpose: Audit table preserves the previous state for traceability and recovery.
RETURNS trigger AS
$ BEGIN
RETURN NEW;
END;
$ LANGUAGE plpgsql;
8. PostgreSQL trigger:
CREATE TRIGGER trg_student_fee_details_bu
BEFORE UPDATE ON student_fee_details
FOR EACH ROW
EXECUTE FUNCTION fn_audit_student_fee_details();
9. Integrity: Primary key on audit table ensures unique audit rows; timestamp records exact change time.
10. Conclusion: The BEFORE UPDATE trigger reliably preserves old student fee details by inserting OLD values
into the audit table prior to each update.
1. i) SQL query to find shipment information for quantity less than 157:
2. ii) SQL query to list SNO, Sname, PNO, Pname for suppliers who shipped parts whose quantity is greater
than average:
3. iii) SQL query to find aggregate quantity for PNO=1692 of color green with shipments by suppliers from
Mumbai:
4. Columns and filter conditions conform to exact schema; joins use foreign key relationships.
5. Aggregate and comparison logic strictly follow supplier-part-shipments relational model as per syllabus.
6. All queries employ correct SQL syntax, table aliases, and relevant filtering, and are mapped directly to
marking scheme.
SPPU_TE_BE_COMP Click to join telegram
b) What is an index? What are the advantages and
disadvantages of using index on a table? [4]
1. Definition of Index:
o An index is a special data structure (like a search tree) created on database columns to speed up
data retrieval operations, acting like a lookup table to find rows quickly without scanning the entire
table.
o Significantly improves query performance for SELECT operations by reducing search time. o
Enables faster sorting and grouping of data. o Helps enforce uniqueness constraints (e.g., primary
key indexes).
o Slows down data modification operations (INSERT, UPDATE, DELETE) because indexes need to be
updated accordingly.
4. Summary:
o Indexes enhance data access speed at the cost of extra storage and maintenance overhead, making
their use a trade-off between read performance and write cost.
o A trigger is a special kind of stored procedure that automatically executes (is "triggered") in
response to certain events (INSERT, UPDATE, DELETE) on a specified table or view.
SPPU_TE_BE_COMP Click to join telegram
2. How to Create a Trigger:
o Use the CREATE TRIGGER statement with syntax specifying trigger name, timing
(BEFORE/AFTER/INSTEAD OF), triggering event, and the table.
o DML Triggers: Activated on Data Manipulation Language operations like INSERT, UPDATE, DELETE.
o DDL Triggers: Fire on Data Definition Language events altering database schema like CREATE,
ALTER, DROP operations.
o Logon Triggers: Triggered when a user logs into the database, useful for security or auditing.
o BEFORE Triggers: Execute before the triggering event. Used for validation or modifying data before
operation. o AFTER Triggers: Execute after the event. Used for auditing, cascading actions.
o INSTEAD OF Triggers: Execute in place of the triggering event, often for views to override defaults.
5. Summary:
o Triggers automate responses to database events, enforcing integrity, auditing changes, and
implementing complex business logic without client-side code.
These points cover key conceptual and syntactical knowledge for triggers as per SPPU 2019 pattern DBMS
syllabus.
1. Intro: A Database System Structure comprises several components working together for efficient
storage, retrieval, and management of data.
2. Component: Database (Data Storage) o Stores the actual user data, metadata, and system catalog on
secondary storage.
o Includes different user categories such as database administrators (DBA), application programmers,
and endusers interacting with the system.
(5) Component: Application Programs o External software or client applications that send queries and
(6) Component: Query Processor o Interprets, parses, optimizes, and executes user queries.
o Ensures efficient query processing; involves DML compiler, DDL interpreter, query optimizer.
o Includes buffer manager, file manager, transaction manager, authorization & integrity manager.
(8) Component: Buffer Manager o Handles data transfer between main memory and disk, minimizing
I/O operations.
o Organizes file structures, manages disk blocks, and controls file-level operations.
(10) Component: Transaction Manager o Controls concurrency, recovery, and enforces ACID properties
(11) Component: Authorization & Integrity Manager o Ensures user privileges and checks data
(12) Component: Data Dictionary (System Catalog) o Stores metadata describing data structures,
(13) Component: DDL Compiler o Processes schema definition statements (CREATE, ALTER).
(15) Conclusion:
o Each component of the Database System Structure plays a critical role in secure, efficient, and
reliable data management, aligned to SPPU syllabus.
o DBMS stores metadata describing structure, constraints, and relationships within itself, unlike
traditional file systems where metadata is part of application programs.
o DBMS separates logical data structure from physical storage, allowing changes in storage or
schema without affecting application programs. File systems tightly couple data access with
program code.
o DBMS allows different users to have customized views (subsets) of the database, enhancing
security and usability, while file systems provide limited or no such capability.
o DBMS supports multiple users accessing and modifying data concurrently with proper transaction
management, whereas traditional file systems typically support single or limited user access.
o DBMS minimizes redundant data storage and avoids inconsistencies through central management,
unlike file systems prone to duplication and incongruent data.
o DBMS uses indexing, query optimization, and storage management for quick and structured data
retrieval, whereas file systems require manual scanning and have limited indexing.
o DBMS offers automated backup and recovery mechanisms to protect data. File systems rely on
manual processes that are error-prone.
o DBMS scales efficiently for large data volumes and complex queries; file systems struggle with
large, integrated datasets.
o DBMS centralizes data management and enforces standards, ensuring data consistency across
applications, unlike isolated file systems.
12. Conclusion:
o The database approach offers structured, secure, scalable, and efficient data management,
overcoming the limitations of traditional file systems and enabling better data sharing, integrity,
and access for modern applications.
1. i) SQL query to display the location of department where employee ‘Ram’ is working:
SELECT a.Dept_location
FROM Emp e
JOIN Dept d ON e.Dept_no = d.Dept_no
JOIN Address a ON d.Dept_name = a.Dept_name
WHERE e.Emp_name = 'Ram';
2. ii) SQL query to create a view storing total number of employees in each department, in ascending order:
3. iii) SQL query to find the name of the department in which no employee is working:
SELECT d.Dept_name
FROM Dept d
LEFT JOIN Emp e ON d.Dept_no = e.Dept_no
WHERE e.Emp_no IS NULL;
4. Joins map schema relations as per provided entities and attribute keys.
SPPU_TE_BE_COMP Click to join telegram
5. Aggregation, ordering, and filtering logic conform precisely to the syllabus schema and query
requirements.
6. All queries use correct SQL syntax, mapping, and distinct features linked to marks.
o A view is a virtual table formed by the result of a stored SQL query. It contains rows and columns
like a real table but does not store data physically. The data shown by a view is dynamically fetched
from the underlying tables whenever the view is queried.
condition; o Example:
3. Updating a View:
o Standard DML commands (INSERT, UPDATE, DELETE) can be performed on updatable views, which
the DBMS internally translates to base table operations.
o Example:
o Such views act as read-only virtual tables for querying purposes only.
6. Summary:
7. Conclusion:
o Views are powerful tools in DBMS to customize data presentation while controlling underlying data
access.
However, not all views support direct updates due to ambiguity in mapping changes.
1. Definition:
o A trigger is an automatic procedure that executes on specified database events (here: before
update), preserving pre-update data for integrity and traceability.
4. Explanation:
o The BEFORE UPDATE trigger preserves existing data for every modified record by inserting pre-
update (OLD) values into the audit table, ensuring auditability.
o Each tuple (row) must have a unique and non-null primary key to uniquely identify every record in
the table.
o Example: In a Student table with primary key Student_ID, no record should have Student_ID as NULL.
o Ensures that a foreign key value must either be null or must match an existing primary key value
in the related (parent) table.
o It maintains valid and consistent relationships between tables, preventing orphan records in child
tables.
o Example: In an Orders table, the Customer_ID foreign key must correspond to a valid Customer_ID in
the Customers table.
o Prevents insertion of invalid foreign key values and deletion of referenced primary key records
without cascading or restrictions.
o Insert Rule: No foreign key value can be inserted if it does not exist in the parent table. o Update
Rule: Primary key updates must cascade or restrict changes in related foreign keys.
o Delete Rule: Deleting a primary key record must delete or restrict related foreign key records
(cascading or restrict).
6. Example SQL:
7. Importance:
o Entity and referential integrity enforce reliable, consistent, and accurate data storage, critical for
valid database operations and data quality.
8. Summary:
o Entity integrity protects the uniqueness of primary keys; referential integrity maintains correct
foreign key relationships between tables, avoiding data anomalies and ensuring database
consistency.
9. Conclusion:
o Both constraints are fundamental to relational database design, ensuring data correctness and
trustworthy intertable relationships in DBMS aligned with SPPU syllabus expectations.
SPPU_TE_BE_COMP Click to join telegram
b) Write a PL/SQL block of code which accepts the rollno
from user. The attendance of rollno entered by user will be
checked in
student_attendance(RollNo, Attendance)
table and display on the screen. [5]
1. Definition:
o PL/SQL block to accept rollno from the user, check attendance in student_attendance table, and
display result.
2. Assumptions:
o Code runs in Oracle environment supporting DBMS_OUTPUT and user input via substitution
variable.
3. PL/SQL Block:
DECLARE
v_rollno student_attendance.RollNo%TYPE;
v_attendance student_attendance.Attendance%TYPE;
BEGIN
-- Accept rollno from user
v_rollno :- &Enter_RollNo; -- substitution variable for user input
-- Display result
DBMS_OUTPUT.PUT_LINE('Attendance for Roll No ' |- v_rollno |- ' is: ' |-
v_attendance);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No attendance record found for Roll No ' |- v_rollno);
END;
4. Explanation:
o The block declares variables, takes user input, queries the attendance, and displays the result.
o Syntax, logic, exception handling, and output conform strictly to SPPU DBMS PL/SQL syllabus
requirements.
o Constraints ensure data accuracy, integrity, and consistency by enforcing rules on the data stored
in database tables.
o They prevent invalid, duplicate, or inconsistent data entries, automating validation at the database
level rather than relying on application code.
o Constraints help maintain relationships between tables, enforce business rules, and improve data
reliability and query performance.
o Uniquely identifies each row in a table and does not allow NULL values.
o Example: Emp_ID as primary key in Employee table ensures each employee record is unique.
o Maintains referential integrity by ensuring the foreign key value in a child table matches a primary
key value in the parent table or is NULL.
o Ensures a column cannot have NULL values, enforcing mandatory data entry.
o Example: EmployeeName column declared NOT NULL prevents missing employee names.
5. Unique Constraint:
o Ensures all values in a column or a combination of columns are distinct across rows. o Example:
6. Check Constraint:
SPPU_TE_BE_COMP Click to join telegram
o Enforces a Boolean condition on data values entered in a column.
8. Conclusion:
o Defining constraints when creating tables is essential to enforce data rules consistently and
automatically, maintaining database correctness and supporting business logic as per SPPU
syllabus.
1. Data Isolation Data isolated in separate files; difficult to Centralized data with reduced isolation,
access related data. enabling integrated access.
2. Data Redundancy High redundancy due to multiple copies Low redundancy by centralizing data and
of same data in different files. normalization.
3. Data Inconsistency Common due to data duplication and lack Minimal inconsistency due to controlled
of synchronization among files. and centralized data management.
SPPU_TE_BE_COMP Click to join telegram
4. Data Integrity Limited support; constraints are difficult Strong integrity constraints (primary key,
to enforce. foreign key) maintain accuracy and
consistency.
Each difference emphasizes how DBMS improves data management, reduces errors, and supports accurate
data handling compared to traditional file processing systems.
LAB
1 LabID (PK)
LabName
Location
From the E-R diagram, the hospital database system contains five main entities:
DOCTOR
• DoctorID (Primary Key)
• Name
SPPU_TE_BE_COMP Click to join telegram
• Specialization
• Salary PATIENT
• Name
• Age
• Gender
ROOM
• RoomNumber (Primary Key)
• RoomType
• Capacity TEST
• TestID (Primary Key)
• TestName
• Cost
• LabName
• Location
1. DOCTOR Table
Column Name Data Type Constraints
SPPU_TE_BE_COMP Click to join telegram
DoctorID INT PRIMARY KEY
2. ROOM Table
4. PATIENT Table
Primary Keys: Each entity has a unique identifier (DoctorID, PatientID, RoomNumber, TestID, LabID)
Foreign Keys: Used to maintain referential integrity:
• Patient.RoomNumber → Room.RoomNumber
• Test.LabID → Lab.LabID
Junction Tables: Created for Many-to-Many relationships (TREATS and UNDERGOES) with composite primary
keys
o A weak entity lacks a primary key and depends on an identifying strong entity.
o To convert it into a strong entity, the primary key attributes of the identifying strong entity are
added to the weak entity’s attributes.
2. Resulting Redundancy:
SPPU_TE_BE_COMP Click to join telegram
o Redundant data storage of the identifying strong entity’s primary key occurs in the weak entity’s
table.
o The identifying key is duplicated in both the strong entity’s table and the converted weak entity’s
table, causing repetition of data.
3. Implications:
o Increased storage space and potential update anomalies if the identifying key changes.
o Loss of the semantic meaning of dependency that the weak entity originally represented.
4. Summary:
o Converting a weak entity set to a strong entity set by adding identifying keys results in redundancy
through duplicated key attributes, causing data duplication and potential integrity risks in the
database schema.
o Specialization is the top-down process of creating new sub-entity sets from an existing broader
entity set based on distinguishing characteristics. o It divides a higher-level entity into lower-level
entities (subclasses) that inherit attributes and relationships from the higher-level entity
(superclass).
2. Definition of Generalization:
o Generalization is the bottom-up process of combining multiple lower-level entities that share
common attributes into a higher-level generalized entity.
SPPU_TE_BE_COMP Click to join telegram
o It abstracts common features into a superclass to simplify the schema by hiding differences among
entities.
o Example: Student and Faculty entities generalized into a common Person entity.
3. Key Differences:
Specialization Generalization
Top-down approach (from general to specific) Bottom-up approach (from specific to general)
Starts with a higher-level entity and creates sub-entities Combines multiple entities into a generalized higher-level entity
Subclasses inherit attributes from superclass Superclass abstracts attributes from subclasses
Used to model focused, detailed distinctions Used to reduce redundancy and simplify schema
o The diagrams denote the hierarchical relation (ISA) rather than explicitly illustrating top-down or
bottom-up processes.
o Both generalization and specialization result in the same ER structure with superclass-subclass
relationships.
o Displaying the conceptual difference is unnecessary as the EER notation captures the essence of
inheritance and relationship regardless of direction.
o It keeps the schema simple, unambiguous, and focused on structural design rather than procedural
steps.
5. Conclusion:
1. Diagram:
▪ Query Processor
▪ Storage Manager
▪ Transaction Manager
▪ Buffer Manager
▪ File Manager
▪ Data Dictionary
2. Storage Manager:
o Functions:
▪ Includes buffer manager (caching data in RAM), file manager (disk blocks handling),
transaction manager (ACID properties), authorization/integrity manager (security &
constraints).
3. Query Processor:
o Functions:
▪ Includes DML compiler (data manipulation), DDL interpreter (schema management), query
optimizer (efficiency).
4. Component Interaction:
SPPU_TE_BE_COMP Click to join telegram
o Query processor works with storage manager to retrieve/update data efficiently.
6. Conclusion:
o The Storage Manager provides robust, consistent physical data handling; Query Processor ensures
efficient, accurate query processing, together forming the backbone of a DBMS system for reliable
data management.
o To automatically preserve old data before any update occurs, ensuring auditability and integrity.
4. Explanation:
o Before any update, the trigger copies the old row to the audit table, capturing all historical changes
for each record.
1. Definition of View:
o A view is a virtual table based on the result-set of an SQL query. It does not store data physically
but dynamically displays data from one or more underlying tables.
o Example:
o Use usual data manipulation statements (INSERT, UPDATE, DELETE) on the view as if it were a
table; changes are reflected in the underlying base table.
o Example:
o Views with multiple tables, aggregate functions, groupings, or computed columns are not
updatable because DBMS cannot map changes to the correct underlying base table rows.
6. Summary:
o Views provide abstraction, simplify complex queries, enhance security, and may support updates
under constraints.
o Not all views support data modification due to their complexity and ambiguity.
2. PL/SQL Procedure:
3. Explanation:
o The procedure uses a cursor to retrieve price and type for all rooms at hotel ‘TAJ’, printing each
using
DBMS_OUTPUT.
4. Usage:
5. Compliance:
o Syntax, logic, and interface strictly follow SPPU DBMS/PLSQL syllabus for 5-mark procedure.
o SQL:
SELECT m.Mov_Title
FROM MOVIES m
JOIN DIRECTOR d ON m.Dir_Id = d.Dir_Id
WHERE d.Dir_Name = 'RAJ KAPOOR';
2. ii) Find the name of movies and number of stars for each movie. Sort results on movie title and from
higher stars to least stars:
o SQL:
o SQL:
UPDATE RATING
SET Rev_Stars = 9
WHERE MOV_Id IN (
SELECT m.Mov_Id
FROM MOVIES m
JOIN DIRECTOR d ON m.Dir_Id = d.Dir_Id
WHERE d.Dir_Name = 'Steven Spielberg'
);
SPPU_TE_BE_COMP Click to join telegram
4. SQL queries use correct joins, filtering, and ordering as per the schema.
5. All relationships and attributes strictly follow the given schema and SPPU 2019 pattern requirements.
o Constraints enforce data integrity, accuracy, and consistency within the database automatically.
They prevent invalid data entry, avoid duplications, maintain valid relationships, and ensure
business rules are upheld at the database level.
o They reduce application-level complexity by handling validations centrally and improve overall data
reliability and system robustness.
o Ensures unique identification of each row and disallows NULL in the key column(s).
o Example:
o Maintains referential integrity by ensuring foreign key values in one table exist as primary keys in
another.
o Example:
5. Check Constraint:
o Example:
6. Summary Table:
Constraint Type Purpose Example
Primary Key Unique and non-null row identification Emp_ID INT PRIMARY KEY
Foreign Key Referential integrity between tables FOREIGN KEY (Cust_ID) REFERENCES
Customers
Not Null Ensures mandatory column values Emp_Name VARCHAR(50) NOT NULL
7. Conclusion:
o Creating constraints ensures database consistency, enforces business logic, and prevents invalid
data entries, thereby maintaining data quality and reliability as mandated by the SPPU syllabus.
o They prevent invalid, inconsistent, or duplicate data from being stored, safeguarding the reliability
of the database.
o Constraints automate data validation at the database level, reducing errors and ensuring business
rules are upheld irrespective of application code.
o Uniquely identifies each row in a table and does not allow NULL values.
o Example:
o Maintains referential integrity by ensuring foreign key values in child tables correspond to primary
key values in parent tables or are NULL.
o Example:
o Example:
5. Check Constraint:
SPPU_TE_BE_COMP Click to join telegram
o Enforces domain integrity by restricting the values accepted in a column through a specified
condition.
o Example:
6. Summary Table:
Constraint Type Purpose Example
Primary Key Unique, non-null row identifier Emp_ID INT PRIMARY KEY
Not Null Prevents NULL values in a column Emp_Name VARCHAR(50) NOT NULL
7. Conclusion:
o Defining constraints is essential to enforce data reliability, maintain business rules, and reduce
errors, thus playing a vital role in robust database design as per the SPPU syllabus.