DBMS Q Bank
DBMS Q Bank
DBMS Q Bank
Favorite
Archived
Backup and
Not efficient Efficient
recovery
Applications:
Student information
Customer information
Stock information
account
sales
DBMS Q BANK 1
Draw and explain three level architecture of DBMS.
1. External level :
It is also called view level. The reason this level is called “view” is because
several users can
view their desired data from this level which is internally fetched from database
with the help of conceptual and internal level mapping.
2. Conceptual level :
It is also called logical level. The whole design of the database such as
relationship among data, schema of data etc. are described in this level.
DBMS Q BANK 2
3. Internal level :
This level is also known as physical level. This level describes how the data is
actually stored in the storage devices. This level is also responsible for
allocating space to the data. This is the lowest level of the architecture.
Decides hardware –
They decides economical hardware, based upon cost, performance and
efficiency of hardware, and best suits organisation. It is hardware which is
interface between end users and database.
Database design –
DBA is held responsible and accountable for logical, physical design, external
model design, and integrity and security control.
Database implementation –
DBA implements DBMS and checks database loading at time of its
implementation.
DBMS Q BANK 3
Explain different levels of data abstraction
Internal Level/Schema
The internal schema defines the physical storage structure of the database.
The internal schema is a very low-level representation of the entire
database. It contains multiple occurrences of multiple types of internal
record. In the ANSI term, it is also called “stored record’.
Conceptual Schema/Level
This logical level comes between the user level and physical storage view.
However, there is only single conceptual view of a single database.
External Schema/Level
An external schema describes the part of the database which specific user
is interested in. It hides the unrelated details of the database from the user.
There may be “n” number of external views for each database.
Explain the DBMS languages with examples: DDL, DML, and DCL.
DDL or Data Definition Language actually consists of the SQL commands that
can be used to define the database schema. It simply deals with descriptions of
the database schema and is used to create and modify the structure of
database objects in the database. DDL is a set of SQL commands used to
create, modify, and delete database structures but not data. These commands
are normally not used by a general user, who should be accessing the database
via an application.
DBMS Q BANK 4
List of DDL commands:
CREATE: This command is used to create the database or its objects (like
table, index,function, views, store procedure, and triggers).
The SQL commands that deals with the manipulation of data present in the
database belong to DML or Data Manipulation Language and this includes most
of the SQL statements. It is the component of the SQL statement that controls
access to data and to the database. Basically, DCL statements are grouped
with DML statements.
DCL includes commands such as GRANT and REVOKE which mainly deal with
the rights, permissions, and other controls of the database system.
DBMS Q BANK 5
REVOKE: This command withdraws the user’s access privileges given by
using the GRANT command.
Pros Cons
DBMS Q BANK 6
Explain Data Independence.
Data Independence
Logical data independence is used to separate the external level from the
conceptual view.
DDL (Data Definition Language): DDL is used to define the structure of the
database. This includes creating tables, defining the columns in those tables,
DBMS Q BANK 7
and specifying the constraints on those columns. DDL statements are not
reversible, meaning that they cannot be rolled back.
UNIT 2
List various mapping cardinalities of E-R diagram.
1. One-to-One (1:1):
Multiple instances of one entity are associated with exactly one instance of
another entity.
DBMS Q BANK 8
Example: Students enroll in multiple courses, and each course has multiple
enrolled students.
2. Unique Constraint:
4. Check Constraint:
5. Default Constraint:
DBMS Q BANK 9
Example: A "Status" column in an "Employee" table can have a default
constraint set to 'Active' so that new employee records are automatically
marked as active.
7. Composite Constraint:
9. Domain Constraint:
DBMS Q BANK 10
An E-R diagram (Entity-Relationship Diagram) is a graphical representation of
the entities and relationships of a database. It is used to model the data of a
database in a way that is easy to understand and maintain.
Differentiate strong entity set and weak entity set. Demonstrate the concept of both
using real-time example using E-R diagram
Primary key Has a unique primary key Does not have a unique primary key
DBMS Q BANK 11
Explain specialization in E-R diagram
Example,
Define: Primary Key, Foreign key, NOT NULL constraints and referential integrity
(Foreign Key) constraint
DBMS Q BANK 12
primary key value for one table are referenced by the column or columns in
another table. This column becomes a foreign key in the second table.
NOT NULL : In SQL, constraints are some set of rules that are applied to the
data type of the specified table. Or we can say that using constraints we can
apply limits on the type of data that can be stored in the particular column of the
table. Constraints are typically placed specified along with CREATE statement.
By default, a column can hold null values.
Allows 1:1, 1:M, and M:N relationships among the entities or members.
Object-Oriented Model
OOD databases support object data persistence, which means that objects can
be stored and retrieved from the database even when the program that created
DBMS Q BANK 13
them is not running.
DBMS Q BANK 14
List the steps in proper sequence in order to convert an ER diagram into tables
Step 1 − Conversion of strong entities
Step 2 − Conversion of weak entity
Step 3 − Conversion of one-to-one relationship
Step 4 − Conversion of one-to-many relationship
Step 5 − Conversion of many-many relationship
Step 6 − Conversion of multivalued attributes
Step 7 − Conversion of n-ary relationship
DBMS Q BANK 15
UNIT 3
Explain keys(Super Key,Candidate Key,Primary Key,Foregin Key,Alternate Key)
here are the different types of keys in a relational database in short and simple
points:
Super key: A super key is a set of one or more attributes that can uniquely
identify each row in a table.
Candidate key: A candidate key is a super key that does not contain any
redundant attributes.
Foreign key: A foreign key is an attribute in one table that refers to the primary
key of another table.
Alternate key: An alternate key is a candidate key that is not chosen to be the
primary key.
Key Definition
A set of one or more attributes that can uniquely identify each row in a
Super key
table.
Candidate key A super key that does not contain any redundant attributes.
Primary key A candidate key that is chosen to uniquely identify each row in a table.
Foreign key An attribute in one table that refers to the primary key of another table.
Alternate key A candidate key that is not chosen to be the primary key.
List the relational algebra operators. Discuss any one such algebra operator with
suitable example.
Relational Algebra Operators:
In relational algebra, there are several fundamental operations used to manipulate
and retrieve data from relational databases. One of these operations is the
Projection operation.
Projection Operation:
DBMS Q BANK 16
Projection is an operation in relational algebra that allows us to select specific
attributes (columns) from a table while eliminating the rest. It is denoted by the
symbol ∏ and is used to produce a new table with only the specified attributes from
the original table.
Input:
To retrieve only the "NAME" and "CITY" attributes from the "CUSTOMER" table, we
can use the projection operation as follows:
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
In this example, the projection operation (denoted by ∏) was used to create a new
table containing only the "NAME" and "CITY" attributes from the original
"CUSTOMER" table, effectively eliminating the "STREET" attribute. This operation
is valuable for extracting specific information and simplifying query results.
DBMS Q BANK 17
Explain all types of join in detail with example
Inner Join : Returns records that have matching values in both tables.
Left Join : Returns all records from the left table, and the matched records from
the right table.
Right Join : Returns all records from the right table, and the matched records
from the left table
Full Outer Join : Returns all records when there is a match in either left or right
table
DBMS Q BANK 18
Feature Open Source DBMS Commercial DBMS
May lack some features that are May have more features than
Features
available in commercial DBMS open source DBMS
May be less secure than commercial May be more secure than open
Security
DBMS source DBMS
Explain the working of Cartesian product Operation and the Division Operation with
an appropriate example
Cartesian Product Operation:
The Cartesian Product in DBMS is an operation used to combine columns from two
relations. It is not typically meaningful on its own but becomes meaningful when
followed by other operations. This operation is also known as a Cross Product or
Cross Join.
Example - Cartesian Product:
Consider two relations, A and B:
Relation A:
Column1 Column2
1 1
1 1
Relation B:
Column1 Column2
1 1
DBMS Q BANK 19
To find all rows from the Cartesian product of A and B where "Column2" has the
value '1', you can use the selection operation (σ):
σ Column2 = '1' (A X B)
Output:
Column1 Column2
1 1
1 1
In this example, the Cartesian product (A X B) is first created, and then a selection
operation is applied to filter rows where "Column2" equals '1'.
Division Operation:
The division operation in DBMS is used when you want to find entities that interact
with all entities in a set of different types of entities. It is typically required for queries
containing the keyword 'all.'
Examples:
2. Retrieve the names of employees who work on all the projects that 'John
Smith' works (company schema):
In this case, the division operation helps find employees who are involved in all
the same projects as 'John Smith.'
The division operation is useful for complex queries involving relationships between
entities and finding entities that meet specific criteria across different types of
entities.
UNIT 4
What is functional dependency? Explain its types in detail
Functional dependencies are constraints that describe the relationship between two
sets of attributes, with one set capable of determining the value of the other. They
DBMS Q BANK 20
are represented as X → Y, where X is a set of attributes that can accurately
determine the value of Y.
There are several types of functional dependencies:
This occurs when the dependent set is always a subset of the determinant.
This type of dependency exists when the dependent set is not a subset of
the determinant.
In cases where the entities within the dependent set are not interdependent,
a multivalued functional dependency occurs.
DBMS Q BANK 21
Let's start with A:
Closure of A (A+):
A → A (Reflexivity)
A → BC (From F)
A → B (Using A → BC and then BC → B, transitivity)
A → D (Using A → B and then B → D, transitivity)
A → E (Using A → BC and then BC → E, transitivity)
So, A+ = {A, B, D, E}
Now, let's compute the closure of B:
Closure of B (B+):
B → B (Reflexivity)
B → D (From F)
B → BC (Using B → D and then D → BC, transitivity)
B → E (Using B → D and then D → E, transitivity)
So, B+ = {B, D, E, C}
Next, let's compute the closure of C:
Closure of C (C+):
C → C (Reflexivity)
C → BC (From F)
C → B (Using C → BC and then BC → B, transitivity)
C → D (Using C → B and then B → D, transitivity)
C → E (Using C → BC and then BC → E, transitivity)
So, C+ = {C, B, D, E}
Now, let's compute the closure of D:
Closure of D (D+):
D → D (Reflexivity)
D → BC (Using D → B and then B → BC, transitivity)
D → E (Using D → BC and then BC → E, transitivity)
So, D+ = {D, B, E, C}
Finally, let's compute the closure of E:
DBMS Q BANK 22
Closure of E (E+):
E → E (Reflexivity)
E → A (From F)
E → BC (Using E → A and then A → BC, transitivity)
E → B (Using E → BC and then BC → B, transitivity)
E → D (Using E → A and then A → D, transitivity)
So, E+ = {E, A, B, D, C}
Step 3: Determine the candidate keys for R.
The candidate keys are the minimal sets of attributes that can uniquely determine
all other attributes. To find the candidate keys, we look for attributes whose closures
include all attributes in the relation schema R (A, B, C, D, E). In this case, A and E
are candidate keys because their closures (A+ and E+) contain all attributes (A, B,
C, D, E).
Therefore, the candidate keys for R are {A, E}.
What is meant by normalization? Write its need. List and discuss various
normalization forms
1. To minimize redundancy.
Forms of Normalization:
DBMS Q BANK 23
Explain Armstrong's axioms
State true or false: Any relation schema that satisfies BCNF also satisfies 3NF
True
UNIT 5
Explain steps of query processing with the help of a neat diagram.
DBMS Q BANK 24
Query Processing is the activity performed in extracting data from the database. In
query processing, it takes various steps for fetching the data from the database.
The steps involved are:
1. Parsing and translation: As query processing includes certain activities for data
retrieval.
Explain linear search and binary search algorithm for selection operation.
Linear Search:
DBMS Q BANK 25
2. Operation: It checks each element from the beginning until the desired element
is found or the list is exhausted.
3. Time Complexity: O(n) in the worst case, where n is the number of elements.
Binary Search:
1. Divide and Conquer: Binary search divides the list into two halves and
eliminates one half based on comparison with the target value.
2. Operation: It compares the target value with the middle element and proceeds
to the left or right half accordingly.
4. Use Case: Ideal for sorted data where quick searches are needed.
3. Cost Estimation: The optimizer estimates the cost of various execution plans
for the query.
5. Plan Selection: The optimizer selects the most cost-effective execution plan
based on the estimated costs.
6. Plan Execution: The chosen plan is executed to retrieve and deliver the
requested data.
8. Result Delivery: The query results are delivered to the user or application.
DBMS Q BANK 26
The External Sort-Merge Algorithm is a method for sorting large datasets that do not
fit entirely in memory (RAM). It divides the dataset into smaller chunks, sorts each
chunk in memory, and then merges these sorted chunks together to produce the
final sorted dataset. Here's an explanation with an example:
Original Dataset: [32, 15, 7, 10, 23, 42, 5, 17]
We want to sort this dataset using the External Sort-Merge Algorithm with a chunk
size of 3 (so each chunk can fit three numbers).
Step 1 - Divide into Chunks:
Initialize the priority queue: [7, 10, 5] (smallest elements from each chunk).
DBMS Q BANK 27
Output: [7, 10, 15, 17, 23, 32]
Output: [5]
The final sorted dataset is: [5, 7, 10, 15, 17, 23, 32, 42].
UNIT 6
Explain B-tree with Example.
B-Tree:
A B-Tree is a specialized m-way tree widely used for disk access. A B-Tree
of order m can have at most m-1 keys and m children. One of the main
reasons for using a B-Tree is its capability to store a large number of keys
in a single node and large key values while keeping the height of the tree
relatively small.
A B-Tree of order m contains all the properties of an M-way tree. Additionally, it has
the following properties:
Every node in a B-Tree except the root node and the leaf nodes contains at
least m/2 children.
example of a B-tree
DBMS Q BANK 28
Root
/ \
10 20
/ \ / \
15 18 25 30
/\ /\
16 17 24 29
1. Fixed Buckets: Static hashing uses a fixed number of buckets or bins to store
data.
Dynamic Hashing:
DBMS Q BANK 29
define sparce index
UNIT 7
List and discuss ACID properties of transactions.
ACID Properties of Transactions:
1. Atomicity:
2. Consistency:
All database constraints and rules are maintained during and after the
transaction.
3. Isolation:
4. Durability:
Data changes are stored safely and are not lost, even in the event of a
crash.
DBMS Q BANK 30
Example: After a successful payment transaction, the record of the payment
is not lost and remains in the database.
ACID properties are crucial for maintaining data integrity and reliability in database
systems, especially in scenarios involving critical transactions.
Aborted: The transaction has failed and all of the changes made by the
transaction have been rolled back.
DBMS Q BANK 31
Transitions between transaction states
A transaction can transition between the following states:
Ensures that the final state of the Ensures that the read and write
database is the same as if the operations of each transaction are
Definition
transactions had been executed equivalent to those of some serial
serially in some order. schedule.
Explain the concurrency problem. How does the strict two phase locking protocol
solve three problems concurrency? Explain with example
DBMS Q BANK 32
Concurrency problems arise in multi-user systems when multiple transactions try to
access and modify shared data concurrently. The three main concurrency problems
are:
1. Lost Updates: When multiple transactions try to update the same data
simultaneously, one update might overwrite the changes made by another
transaction, leading to lost information.
The Strict Two-Phase Locking Protocol helps to address these issues by enforcing
strict rules on how transactions acquire and release locks on data.
This protocol ensures that conflicting operations don't overlap, thereby preventing
lost updates, uncommitted data, and inconsistent retrievals by allowing only one
transaction to modify shared data at a time, ensuring data integrity and consistency.
DBMS Q BANK 33
Write differences between shared lock and exclusive lock
Shared Lock:
3. Access Restriction: Allows concurrent read access but prohibits write access
by transactions holding shared locks.
4. Conflict: Doesn’t conflict with other shared locks but conflicts with exclusive
locks.
Exclusive Lock:
4. Conflict: Conflicts with both shared and exclusive locks, preventing any other
transactions from accessing the locked resource until released.
DBMS Q BANK 34
contention environments.
Shared lock (S lock): Allows multiple transactions to read the same data
concurrently.
DBMS Q BANK 35
Exclusive lock (X lock): Grants exclusive access to data, allowing only one
transaction to read or write the data.
2PL protocol:
1. Growing phase: During this phase, the transaction acquires all locks it needs
for data modification. It cannot release any locks until the growing phase is
complete.
Benefits of 2PL:
2PL offers several benefits:
Prevents dirty reads: Ensures that a transaction doesn't read data that has
been modified but not yet committed by another transaction.
Prevents deadlocks: Deadlocks occur when two transactions wait for each
other to release locks. 2PL's strict ordering of lock acquisition and release helps
prevent deadlocks.
Conclusion:
2PL is a robust and effective concurrency control mechanism that plays a crucial
role in maintaining data integrity and consistency in database systems.
DBMS Q BANK 36
Schedules can be categorized into two main types:
DBMS Q BANK 37
2. Commit phase: The coordinator sends a "commit" message to all participating
nodes, instructing them to commit the transaction. Each node applies the
transaction's changes to its local data and resources and sends an
acknowledgment message to the coordinator. Once all acknowledgments are
received, the transaction is considered fully committed.
Benefits of 2PC:
Robustness against failures: Can handle failures at any node during the
commit process, ensuring that the transaction is either fully committed or rolled
back consistently across all nodes.
Applications of 2PC:
Conclusion:
2PC is a widely used and reliable protocol for managing distributed transactions,
ensuring data integrity and consistency across multiple nodes in a distributed
system. Its two-phase approach provides a structured and predictable way to
commit or roll back transactions, preventing inconsistencies and maintaining the
integrity of distributed data
UNIT 8
Explain cryptography techniques to secure data. 4
DBMS Q BANK 38
Cryptography is a crucial aspect of data security, employing mathematical
techniques to transform information into an unreadable format, making it
inaccessible to unauthorized parties. By encrypting data, we safeguard sensitive
information from unauthorized access, theft, or modification.
Here's a simplified explanation of cryptography techniques for data security:
5. Data encryption algorithms: Data encryption algorithms convert plain text into
ciphertext, an unintelligible form that can only be decrypted with the appropriate
key. This protects data from unauthorized access and ensures its confidentiality.
1. Injection Point: Attackers exploit vulnerable input fields (e.g., login forms,
search bars) by inserting malicious SQL commands.
DBMS Q BANK 39
2. Malicious SQL Code: Attackers insert SQL statements (queries) within input
fields to manipulate the database or retrieve sensitive information.
3. Goal: Gain unauthorized access, manipulate, or extract data from the database
by altering SQL queries.
4. Impact: Can lead to data theft, unauthorized access, data corruption, or even
complete control of the database.
DAC (Discretionary Access Control) and MAC (Mandatory Access Control) are
models used in computer security to manage access to resources. Here are simple
points explaining both:
DAC (Discretionary Access Control):
3. Example: File systems that allow users to set permissions (read, write,
execute) for files and folders based on their discretion use DAC.
2. Rigid Control: Access decisions are based on predefined rules set by the
system or security administrator. Users cannot change or override these rules.
DBMS Q BANK 40
on their clearance level, and they can't modify these access permissions
themselves.
DBMS Q BANK 41
access to systems or services. or actions users/entities are allowed to
access or perform.
1. Symmetric Encryption:
How it Works: The sender and receiver share the same secret key. Data is
encrypted using this key and decrypted using the same key.
How it Works: Public key encrypts data while the private key decrypts it.
Information encrypted with the public key can only be decrypted with the
corresponding private key.
3. Hash Functions:
How it Works: Irreversibly transforms input data into a unique hash value.
The same input always produces the same output.
4. Hybrid Encryption:
DBMS Q BANK 42
Explanation: Combines symmetric and asymmetric encryption for better
security and efficiency.
5. Quantum Encryption:
Each encryption scheme serves different purposes and has varying levels of
security. They are used based on specific requirements like performance, security
needs, and the nature of data being protected.
UNIT 9
Write SQL statements (Query) for following tables:
T1(rollno, stuname, age, city, branchcode)
T2(branchcode, branchname)
DBMS Q BANK 43
2. Select avg(age) from T1;
Count():
Sum():
Sum(salary): Sum of all non-null values in the "salary" column, i.e., 310.
Sum(Distinct salary): Sum of all distinct non-null values in the "salary" column,
i.e., 250.
Avg():
Min(salary): Minimum value in the "salary" column (excluding NULL), i.e., 40.
DBMS Q BANK 44
on individual tables, views, sequences or procedures.
Revoke :
The GRANT (privilege) statement grants privileges on the database as a whole or
on individual tables, views, sequences or procedures.
UNIT 10
Write short note on cursor.
The set of rows the cursor holds which is called the active set (active data set).
DBMS Q BANK 45
• They are also created when a SELECT statement that
returns just one row is executed.
• We cannot use implicit cursors for user defined work.
• Explicit cursors
Example:
Consider a database table for a bank that stores customer account information. The
bank has a business rule that requires all accounts to have a minimum balance of
$100. To enforce this business rule, the bank can create a trigger that is executed
whenever a withdrawal is made from an account. The trigger will check the account
balance after the withdrawal and raise an error if the balance falls below $100.
Here is a pseudocode example of the trigger:
Trigger: account_balance_check
Event: withdrawal
This trigger will ensure that no account balance ever falls below $100.
DBMS Q BANK 46
Triggers can be used to implement a variety of other business rules, such as:
Triggers can also be used to automate tasks, such as sending email notifications or
generating reports.
Overall, triggers are a powerful tool that can be used to improve the integrity and
functionality of database systems.
Example:
Consider a database for a bank that stores customer account information. The bank
has a stored procedure that is used to open new accounts. The stored procedure
takes the customer's name, address, and initial deposit amount as parameters and
inserts a new record into the customer account table. The stored procedure also
verifies that the initial deposit amount is greater than zero and that the customer's
address is valid.
Here is a pseudocode example of the stored procedure:
Stored procedure: open_account
This stored procedure encapsulates the logic for opening a new account into a
single unit. This makes it easier to maintain and reuse the logic.
Stored procedures can be used to implement a variety of other operations, such as:
DBMS Q BANK 47
Transferring money between accounts
Generating reports
Write a PL/SQL code to print sum of the even numbers between 1 to 100
here is a PL/SQL code to print the sum of the even numbers between 1 to 100:
Code snippet
DECLARE
even_sum NUMBER := 0;
BEGIN
FOR i IN 2..100 BY 2 LOOP
even_sum := even_sum + i;
END LOOP;
This code will declare a variable called even_sum to store the sum of the even
numbers. Then, it will use a FOR loop to iterate over all even numbers from 2 to
100. For each even number, the code will add the number to the even_sum variable.
Finally, the code will use the DBMS_OUTPUT.PUT_LINE() procedure to print the value of
the even_sum variable to the console.
To execute this code, you can use the following command:
This will execute the PL/SQL code and print the sum of the even numbers between
1 to 100 to the console.
DBMS Q BANK 48