QUESTION BANK
1. Recall an important of a primary key. (2M)
A primary key uniquely identifies each record in a table. It ensures data integrity and
consistency by preventing duplicate records.
2. Relate data and information. (2M)
Data is raw, unprocessed facts and figures that lack context or meaning on their own.
Information is data that has been processed, organized, and interpreted to give it context and
meaning.
3. Find GROUP BY and HAVING for data aggregation. (2M)
The GROUP BY clause is used to group rows that have the same values into summary
rows.
The HAVING clause is used to filter groups of data after the GROUP BY operation.
4. Relate where you might want to avoid generating a Cartesian product. (2M)
Large Datasets, Missing Relationships, Complex Queries, Performance Optimization
5. Relate the UNIONALL operator work for combine result into single result set. (2M)
The UNION ALL operator in SQL combines the results of two or more SELECT statements into a
single result set, retaining all rows including duplicates. (2M)
6. Recall sub queries and its type. (2M)
Subqueries are nested SELECT statements within a larger SQL query. They are used to perform
calculations, filter results, or create more complex queries. (1M)
Types of Subqueries: (1M)
1. Scalar Subqueries:
2. Multiple-Row Subqueries:
3. Correlated Subqueries:
7. Outline the purpose of DDL and DML Command in SQL. (2M)
Data Definition Language (DDL) and Data Manipulation Language (DML) are two
fundamental components of SQL (Structured Query Language) used to interact with databases.
DDL (Data Definition Language)
Purpose: Defines the structure of a database, including tables, columns, data types, and
relationships.
DML (Data Manipulation Language)
Purpose: Used to manipulate the data within a database, including inserting, updating, deleting,
and retrieving data.
8. List the advantage of Revoke command in SQL. (2M)
The REVOKE command in SQL is used to remove privileges granted to users or roles. Here are
some of its key advantages:
1. Security Enhancement
2. Data Integrity Protection
3. Auditing and Compliance
4. Performance Optimization
9. Summarize the first normal form (1NF) and its importance for eliminating data redundancy.
(2M)
First Normal Form (1NF) is a fundamental normalization rule in database design that ensures
data is stored in a structured and consistent manner.
Importance of 1NF for eliminating data redundancy:
Reduces data duplication: By ensuring that each attribute contains a single value, 1NF
prevents the duplication of data within a table. This reduces storage requirements and
makes the database more efficient.
Improves data integrity: 1NF helps maintain data consistency and accuracy. When data is
stored in a structured format, it is less likely to be corrupted or misinterpreted.
10. Compare redo and undo logs used for recovery. (2M)
Feature Redo Log Undo Log
Purpose Record changes for recovery Record information for undoing changes
Content Before and after images Before image
Recovery process Replay changes Reverse changes
Types Physical, logical N/A
Part- B (5 x 16 = 80 Marks)
Answer ALL the Questions
11. a. Apply the components of an Entity-Relationship (ER) Diagram for course registration
system. (16M)
Or
b. Identify the concept of keys in a database. Discuss different types of keys with examples.
A key in a database is a set of attributes (columns) that uniquely identifies a record
(row) within a table. It plays a crucial role in maintaining data integrity and
establishing relationships between tables. (4M)
Types of Keys (12M)
Super Key
Candidate Key
Primary Key
Alternate Key
Foreign Key
12. a. Solve different outer join types (left, right, full) in SQL, analyzing how they handle
missing data and retrieve relevant information even with absent data points. Provide
code examples demonstrating their use cases.
Left Outer Join (LEFT JOIN) (6M)
Preserves all rows from the left table.
Includes matching rows from the right table.
Right Outer Join (RIGHT JOIN) (6M)
Preserves all rows from the right table.
Includes matching rows from the left table.
Full Outer Join (FULL OUTER JOIN) (4M)
Preserves all rows from both tables.
Includes matching rows from both tables.
If there's no match in either table, NULL values are returned for the missing columns.
Or
b. Organize the concept of aggregate functions (GROUP BY, COUNT, SUM, AVG, etc.)
with examples demonstrating their usage in summarizing data.
Understanding Aggregate Functions (10M)
Aggregate functions operate on a set of values and return a single value. They are commonly
used to summarize data. Here are some common aggregate functions:
COUNT(*): Counts the number of rows in a table or group.
SUM(column_name): Calculates the total sum of a numeric column.
AVG(column_name): Calculates the average of a numeric column.
MIN(column_name): Returns the minimum value in a column.
MAX(column_name): Returns the maximum value in a column.
GROUP BY Clause (6M)
The GROUP BY clause is used to group rows that have the same values into summary rows.
This enables calculations on groups of data.
Aggregate functions are used to summarize data.
GROUP BY is used to group data before applying aggregate functions.
Combining GROUP BY with aggregate functions allows for powerful data analysis.
13. a. Identify subqueries used in select from and where clauses with example.
Subqueries are queries nested within other queries. They are used to perform more complex
data manipulation and retrieval.
Subqueries in SELECT Clauses (8M)
Purpose: Calculate derived values or aggregate functions for each row in the outer
query.
Syntax:
SQL
SELECT column1, column2, (subquery) AS derived_column
FROM table1;
Example: Calculate the average salary for each department:
SQL
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department;
Subqueries in the FROM clause are used to create derived tables that can be joined with
other tables or used in the outer query's WHERE or HAVING clauses. This technique allows
for more complex data manipulation and retrieval. (8M)
Syntax:
SQL
SELECT column1, column2, ...
FROM (subquery) AS derived_table
JOIN table2 ON derived_table.column = table2.column
WHERE condition;
Example: Find the average salary for each department and then select departments with an
average salary above a certain threshold.
SQL
SELECT department, avg_salary
FROM (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
) AS dept_avg_sal
WHERE avg_salary > 50000;
Or
b. Choose the set operators (Union, Unionall, Intersect and Minus) for combining and
comparing data across multiple result sets.
Choosing the Right Set Operator
Set operators in SQL are used to combine or compare the results of multiple SELECT
statements. Here's a breakdown of each operator and when to use them: (2M)
UNION (4M)
UNIONALL (4M)
INTERSECT (4M)
MINUS (or EXCEPT) (4M)
14. a. Examine the DML, DDL commands in SQL for serving a specific purpose in the
management and interaction with a database.
Applying DML and DDL Commands in SQL
DML (Data Manipulation Language) (8M)
Purpose: Used to manipulate data within a database, including inserting, updating, deleting,
and retrieving data.
DDL (Data Definition Language) (8M)
Purpose: Used to define the structure of a database, including creating, modifying, and
deleting tables, columns, and other database objects.
Or
b. Simplify views and indexes in SQL for optimizing database performance and managing
data effectively. Give Example.
Simplifying Views: (8M)
Minimize Complexity
Use Materialized Views
Avoid Redundant Views
Simplifying Indexes: (8M)
Identify Frequently Accessed Columns
Avoid Redundant Indexes
Consider Index Types
Monitor Index Usage
15. a. Simplify an example scenario demonstrating the need for database normalization to
eliminate data redundancy.
A company maintains a database to track customer orders. The database table Orders contains
the following columns (16M)
Order ID
Customer Name
Customer Address
Product Name
Product Price
Quantity
Problem:
If a customer places multiple orders for the same product, the customer's name, address, and
product information will be repeated for each order. This leads to data redundancy.
Normalization:
To eliminate redundancy, we can create two separate tables:
1. Customers:
o Customer ID
o Customer Name
o Customer Address
2. Orders:
o Order ID
o Customer ID
o Product ID
o Quantity
3. Products:
o Product ID
o Product Name
o Product Price
Or
b. Examine the how PL/SQL blocks can be used to encapsulate complex logic within the
database.
PL/SQL Blocks: Encapsulating Complex Logic within the Database (16M)
PL/SQL (Procedural Language/SQL) is a procedural extension of SQL that allows you to
write complex logic and procedures within the database. PL/SQL blocks are the fundamental
building blocks of PL/SQL code, providing a structured way to organize and execute code.
Basic Structure of a PL/SQL Block
A PL/SQL block consists of three main sections:
1. DECLARE section: This is where you declare variables, cursors, and other objects
that will be used within the block.
2. BEGIN section: This is where you write the executable statements of the block.
3. END section: This marks the end of the block.
Types of PL/SQL Blocks
1. Anonymous blocks: These are blocks that are not associated with any specific stored
object (e.g., procedure, function, trigger). They are often used for one-time execution
or testing purposes.
2. Named blocks: These blocks are associated with stored objects (e.g., procedures,
functions, triggers). They can be reused multiple times within the database.
Encapsulating Complex Logic
PL/SQL blocks can be used to encapsulate complex logic within the database for several
reasons:
Modularity: Breaking down complex logic into smaller, reusable blocks improves
code organization and maintainability.
Performance: PL/SQL procedures and functions can be compiled and stored in the
database, resulting in faster execution times compared to executing SQL statements
directly.
Data validation: PL/SQL blocks can be used to implement data validation rules and
ensure data integrity.
Conditional logic: PL/SQL provides control flow statements (IF-THEN-ELSE,
CASE, LOOP) for implementing conditional logic and complex decision-making
processes.
Error handling: PL/SQL allows you to handle exceptions and errors gracefully,
preventing unexpected behavior.
1. Recall the advantages of a DBMS over a file system. (2M)
Data Integrity, Data Security, Data Sharing, Data Independence
2. Outline cardinality in the context of relationships. (2M)
Define cardinality as the number of instances of one entity related to another.
Briefly explain the four types of cardinalities: one-to-one, one-to-many, many-to-one and
many-to-many.
Provide a simple example for each type.
3. Find the use of COUNT () function in aggregate queries. (2M)
The COUNT () function is used to determine the number of rows in a table or the
number of rows that meet a specific condition.
4. Rephrase an equijoin in SQL. (2M)
An equijoin combines rows from two tables based on the equality of a specific column in
both tables.
5. Interpret the set operators available in SQL. (2M)
SQL set operators are used to combine the results of two or more SELECT statements into a
single result set. They are particularly useful for performing operations like union,
intersection, and difference between sets of data.
6. Compare UNION and UNION ALL. (2M)
Feature UNION UNION ALL
Duplicate
Rows Removes duplicate rows Retains all rows, including duplicates
Generally slower due to duplicate Typically faster due to avoiding duplicate
Performance removal checks
Syntax SELECT ... UNION SELECT ... SELECT ... UNION ALL SELECT ...
When you need all rows, regardless of
Use Case When you want unique results duplicates
7. Define DML in SQL with example. (2M)
DML (Data Manipulation Language) is a set of SQL statements used to modify the data
within a database. These statements allow you to insert, update, delete, and retrieve data
from tables.
Example: INSERT INTO customers (customer_id, customer_name, city)
VALUES (1, 'John Doe', 'New York');
8. List different data types available in SQL. (2M)
SQL provides a variety of data types to represent different kinds of data. Here are some commonly
used data types:
Numerical Data Types
INTEGER: Stores whole numbers (e.g., 1, 100, -50)
DECIMAL: Stores numbers with a decimal point (e.g., 3.14, 12.50)
NUMERIC: Similar to DECIMAL, but offers more precise control over scale and
precision.
FLOAT: Stores approximate floating-point numbers (e.g., 1.23456789)
REAL: Similar to FLOAT, but with a smaller range.
9. Define normalization. (2M)
Normalization is a process in database design that organizes data into tables to minimize
redundancy and improve data integrity. It involves breaking down large tables into smaller, more
manageable ones, and ensuring that data is stored in a consistent and efficient manner.
10. Interpret ACID properties of transactions. (2M)
The ACID properties (Atomicity, Consistency, Isolation, Durability) are fundamental
characteristics that ensure the reliability and integrity of database transactions.
Part- B (5 x 16 = 80 Marks)
Answer ALL the Questions
11. a. Identify the need for a DBMS in detail. Compare and contrast the file system approach
with the database approach.
Need for DBMS: 4 marks
File System approach: 4 marks
Database Approach: 4 marks
Comparison Table: 4 marks
Or
b. Build an ER diagram for a library system. Identify entities, attributes, and relationships.
Specify the cardinality of relationships.
Entities, Attributes,Relationships and cardinality of relationships(8M)
ER diagram(8M)
12. a. Organize various single row functions available for character manipulation in SQL with
examples.
Single-row functions operate on a single row of data and return a single value.
Here are some common character manipulation functions:
Case Conversion Functions (16M)
UPPER(string): Converts a string to uppercase.
LOWER(string): Converts a string to lowercase.
INITCAP(string): Capitalizes the first letter of each word.
SUBSTR(string, start_position, length): Extracts a substring from a string.
LENGTH(string): Returns the length of a string.
CONCAT(string1, string2): Concatenates two strings.
Removes leading or trailing spaces from a string.
TRIM(string):
Or
b. Utilize the concept of joins in relational databases and illustrate different types of joins
(Equijoins, Non-equi Joins, Self Joins, Outer Joins) with detailed examples using SQL.
Equijoin (4M)
An equijoin compares columns from two tables using the equal (=) operator.
Non-Equi Join (4M)
A non-equi join uses comparison operators other than equal (=), such as <, >, <=, >=.
Self Join (2M)
A self join joins a table to itself based on a related column.
Outer Joins (6M)
Outer joins include rows that do not have matches in the other table.
Left Outer Join: Returns all rows from the left table, and the matched rows from the
right table.
Right Outer Join: Returns all rows from the right table, and the matched rows from
the left table.
Full Outer Join: Returns all rows when there is a match in either left or right table.
13. a. Build code examples of Single row subquery and Multiple row subquery.
Single-Row Subquery (8M)
Key Points:
Returns a single value from the subquery.
The subquery must return exactly one row and one column.
The outer query uses this single value as part of its comparison or calculation.
Example:
SQL
SELECT employee_name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Multiple-Row Subquery (8M)
Key Points:
Returns multiple rows from the subquery.
The outer query can use these multiple values for comparison, calculation, or joining.
Often used with IN, EXISTS, or ANY/ALL operators.
Example:
SQL
SELECT department_name
FROM departments
WHERE department_id IN (SELECT department_id FROM employees WHERE salary >
50000);
Or
b. Model the set operators can be combined with aggregate functions for advanced analysis.
Set operators (12M)
UNION, UNION ALL, INTERSECT, EXCEPT
allow you to combine the result sets of multiple queries. When combined with aggregate
functions (COUNT, SUM, AVG, MIN, MAX), you can perform more complex analyses.
Example: (4M)
14. a. Analyze different ways to define primary keys, including composite primary
keys with multiple columns.
A primary key is a unique identifier for each row in a table. It
ensures data integrity by preventing duplicate records. There are
several ways to define primary keys in SQL:
1.Single-Column Primary Key (4M)
2. Composite Primary Key (4M)
3. Using PRIMARY KEY Constraint (4M)
4. Using AUTO_INCREMENT (MySQL) (4M)
Or
b. Inspect code examples demonstrating advanced DML functionalities (e.g., INSERT with
SELECT INTO, conditional UPDATE).
INSERT with SELECT INTO (8M)
This statement allows you to insert data into a table from the results of another query.
Conditional UPDATE(8M)
You can use a CASE expression within an UPDATE statement to conditionally update values
based on certain conditions.
15. a. Analyze how the Third Normal Form (3NF) and Boyce Codd Normal form (BCNF) used
in database design.
Third Normal Form (3NF) and Boyce-Codd Normal Form (BCNF) are two normalization
levels used in database design to ensure data integrity and minimize data redundancy. They are
primarily concerned with functional dependencies between attributes.
Third Normal Form (3NF) –(8M)
A relation is in 3NF if it satisfies the following conditions:
1. First Normal Form (1NF): Every attribute must contain atomic values.
2. Second Normal Form (2NF): Every non-key attribute must be fully dependent on the
primary key.
3. Third Normal Form (3NF): There is no transitive dependency. A transitive
dependency occurs when there is a functional dependency of the form: A -> B and B ->
C, and A does not directly determine C.
Boyce-Codd Normal Form (BCNF)-(8M)
A relation is in BCNF if it satisfies the following condition:
Every determinant is a superkey. A determinant is an attribute or set of attributes that
functionally determines another attribute. A superkey is a set of attributes that contains
a primary key.
Relationship between 3NF and BCNF
All relations in BCNF are also in 3NF.
However, not all relations in 3NF are in BCNF.
Or
b. Compare and Contrast between shared locks and exclusive locks with examples.
Shared Locks and Exclusive Locks are mechanisms used in database systems to control
concurrent access to data. They ensure data consistency and prevent conflicts during read and
write operations.
Shared Locks (8M)
Multiple transactions can acquire a shared lock on the same data simultaneously.
A shared lock allows transactions to read the data but prevents them from modifying
it.
Shared locks are compatible with other shared locks but incompatible with exclusive
locks.
Example:
Multiple users can read the same product information from a database at the same time.
Exclusive Locks (8M)
Only one transaction can acquire an exclusive lock on the same data at a time.
An exclusive lock allows a transaction to read and modify the data.
Exclusive locks are incompatible with both shared and exclusive locks.
Example:
A user is updating the quantity of a product in inventory. An exclusive lock is acquired
on the product record to prevent other users from reading or modifying the same data
while the update is in progress.Comparison Table
Feature Shared Lock Exclusive Lock
Incompatible with all
Compatibility Compatible with other shared locks
locks
Read/Write Read-only Read-write
Multiple
Yes No
transactions
Multiple users reading product User updating
Example
information inventory