DBMS Top Interview Questions
DBMS Top Interview Questions
2. Database Tier :
- Function : This layer consists of the DBMS and the database where data is
stored. The client communicates directly with the DBMS to perform data
operations.
- Example : A desktop application that connects directly to a MySQL or SQLite
database.
### 3. Single-Tier Architecture
In a single-tier architecture, both the application and database reside on the
same system. This architecture is often used for small-scale applications or for
development purposes.
1. Single Layer :
- Function : Both application logic and database management are handled by a
single system. This is typical in small desktop applications where the DBMS and
user interface are on the same machine.
- Example : Microsoft Access or local SQLite databases.
3. Data Control Language (DCL): Used to control access to data within the
database. It includes commands like `GRANT` and `REVOKE` to manage
permissions.
- Example : `GRANT SELECT ON Employee TO user1;`
3. Relational Data Model : Represents data in tables (relations) with rows and
columns, and uses keys to establish relationships between tables.
Example: An RDBMS with tables for customers, orders, and products, where
foreign keys link them.
Need: Data models are crucial for defining the structure and organization of data,
ensuring that it meets the requirements of applications and users. They help in
designing databases, querying data, and maintaining data integrity and
consistency.
Ques 9. What is Data Abstraction in DBMS?
Definition : Data abstraction in a Database Management System (DBMS) is the
process of hiding the complexities of the database system and presenting only the
necessary details to the users. It allows users to interact with data at a high level
without needing to understand the underlying implementation details.
Levels of Data Abstraction :
1. Physical Level : This is the lowest level of abstraction, which describes how
data is physically stored in the database. It involves the details of data storage
structures, file formats, and indexing.
Example : Information about how data is organized on disk and how indexes are
used to speed up data retrieval.
2. Logical Level : This level describes what data is stored in the database and the
relationships between the data. It defines the structure of the data without
considering how it is physically stored.
Example : The schema of the database, including tables, columns, and
relationships between tables.
3. View Level : This is the highest level of abstraction, which provides users with
different perspectives of the data. It focuses on what data is relevant to a
particular user or application, hiding the details of the logical and physical levels.
Example : Customized views that show only specific columns or rows of a table,
tailored to the needs of different users or applications.
Need : Data abstraction is essential for:
o Simplifying Interaction : Users can interact with the database using high-
level queries without worrying about how data is stored or managed.
o Improving Security : Sensitive data can be hidden from users who do not
need to access it.
o Facilitating Data Independence : Changes to the physical or logical
structure of the database do not affect the way users interact with the data.
Overall, data abstraction enhances usability, security, and flexibility in database
systems by providing a simplified and user-focused view of the data.
Ques 10. What do you mean by Transparent DBMS?
Definition: A transparent DBMS is a database system that hides the complexity of
database operations from the users. Users interact with the data through simple
queries without needing to understand how data is stored, managed, or
processed internally.
Use Case/Example : In cloud-based applications, users can access and
manipulate data stored in remote servers without knowing the underlying
infrastructure or data management techniques.
Need : Transparency in DBMS is essential for simplifying database usage. It
ensures that users can focus on retrieving and updating data without worrying
about the complexities of data storage, recovery, or integrity maintenance.
1. Physical Level:
Definition : The physical level is the lowest level of data abstraction. It describes
how data is physically stored in the database. This includes details about data
storage structures, file formats, indexing methods, and how data is accessed on
the storage media.
Example : Information about how tables are stored on disk, the use of B-trees or
hash indexes for quick data retrieval, and the specifics of data compression
techniques.
Need : This level is crucial for database administrators who need to manage
data storage efficiently and optimize performance.
2. Logical Level :
Definition: The logical level represents what data is stored in the database and
the relationships between the data. It defines the database schema, including
tables, columns, data types, and constraints, without focusing on how this data is
physically stored.
Example: The schema design that specifies a `Customer` table with attributes
like `CustomerID`, `Name`, and `Address`, and the relationships between the
`Customer` table and an `Order` table.
Need : This level is important for database designers and developers as it
provides a blueprint of the database structure and ensures data integrity and
consistency.
3. View Level :
Definition : The view level is the highest level of data abstraction. It defines how
data is presented to users and applications, focusing on what data is visible to
different users or applications. It involves creating views or customized subsets of
data tailored to specific needs.
Example : A view that presents only the `Name` and `Email` of employees to a
user while hiding other sensitive details like salary or job title.
Need : This level enhances usability and security by providing users with
relevant data while abstracting away the complexities of the underlying database
structure.
These three levels of data abstraction work together to simplify database
management, enhance security, and improve the overall efficiency of data
handling.
Ques 12. What is a Relationship?
Definition: In the context of relational databases, a relationship refers to the
association or connection between two or more tables (relations). These
relationships are established through keys, typically foreign keys, which link
records in one table to records in another, facilitating the retrieval of related data.
Types of Relationships:
1. One-to-One (1:1): Each record in Table A is related to exactly one record in
Table B, and vice versa.
Example: A table `Person` and a table `Passport` where each person has one
unique passport.
2. One-to-Many (1:N) : A record in Table A can be related to multiple records in
Table B, but each record in Table B is related to only one record in Table A.
Example: A table `Department` and a table `Employee` where each
department can have multiple employees, but each employee belongs to only
one department.
Need : Relationships are crucial for organizing and querying data across multiple
tables, ensuring data integrity, and facilitating complex queries and reporting.
They help in efficiently managing and accessing related data within a relational
database.
Need : The relation schema is essential for ensuring that data is stored
consistently and adheres to predefined formats and constraints. It serves as a
guideline for creating and managing tables in the database.
2. Relation
Definition : A relation is a subset of the Cartesian product of a set of attributes,
essentially representing a table in a relational database. It consists of tuples
(rows) where each tuple has a set of values corresponding to the attributes
defined in the relation schema.
Need : The relation is fundamental for storing and retrieving data in a structured
format. It allows data to be organized, queried, and manipulated efficiently
according to the relation schema.
4. TRUNCATE : Used to remove all rows from a table while keeping the structure
intact. It is faster than using `DELETE` because it does not generate individual
row delete operations.
Example : `TRUNCATE TABLE Employee;`
Need :
o Database Design : DDL commands are essential for setting up and modifying
the database schema to match the requirements of the application.
o Data Integrity : By defining constraints and data types, DDL helps in
maintaining data integrity and enforcing business rules.
o Database Maintenance : DDL is used for managing and reorganizing database
structures, which is crucial for performance tuning and adapting to changing
needs.
DDL plays a crucial role in the initial setup and ongoing management of the
database structure, ensuring that the data is organized and maintained
effectively.
2. INSERT : Adds new rows of data into a table. It specifies the table and the
values to be inserted into each column.
Example : `INSERT INTO Employee (ID, Name, Salary) VALUES (1, 'Alice Smith',
6000);`
3. UPDATE : Modifies existing rows in a table. It allows users to change the values
in specified columns based on a condition.
Example : `UPDATE Employee SET Salary = 6500 WHERE ID = 1;`
Need : Data Management : DML is crucial for interacting with and managing the
data stored in the database, allowing users to perform everyday operations.
Data Retrieval : It provides a way to access and analyze data, which is essential
for generating reports, making decisions, and conducting analyses.
Data Maintenance : DML commands are used to keep data up-to-date and
accurate, reflecting changes in real-world scenarios.
DML commands are fundamental for the operation of any database system, as
they facilitate the manipulation and retrieval of data to support various
applications and user needs.
2. Second Normal Form (2NF) : Achieved when a table is in 1NF and all non-key
attributes are fully functionally dependent on the entire primary key.
Example : In a table with `StudentID` and `CourseID` as a composite key,
attributes like `CourseName` should depend on `CourseID` alone, not on
`StudentID`.
3. Third Normal Form (3NF) : Achieved when a table is in 2NF and all attributes
are functionally dependent only on the primary key, with no transitive
dependencies (i.e., non-key attributes should not depend on other non-key
attributes).
Example : In a table of `Employee`, if `EmployeeID` is the primary key,
`Department` should not depend on `ManagerName` but directly on
`EmployeeID`.
6. Fifth Normal Form (5NF) : Ensures that the table can be reconstructed from
smaller tables without loss of information. It deals with cases where information
can be represented in multiple ways.
Example : Decomposing a table where multiple entities are involved into
separate tables to avoid redundancy.
Need : Normalization is essential for creating efficient, scalable, and
maintainable databases. It helps in reducing data anomalies, optimizing storage,
and ensuring that the database accurately reflects the real-world entities and
relationships it is designed to model.
Trade-Offs :
Increased Redundancy : Denormalization introduces redundancy, which can
lead to data anomalies and increased storage requirements.
Data Consistency Challenges : Managing data consistency becomes more
complex because updates must be propagated to redundant data, increasing the
risk of inconsistencies.
Denormalization is often used selectively and strategically, balancing the need for
performance improvements with the potential downsides of increased
redundancy and complexity.
2. Attributes :
- Definition : Attributes are the properties or characteristics of entities. They
describe the data stored within an entity.
- Example : For the `Student` entity, attributes might include `StudentID`,
`Name`, and `DateOfBirth`.
3. Entity Sets :
- Definition : An entity set is a collection of similar entities. It represents a table
in the database where each row corresponds to an instance of the entity.
- Example : The `Student` entity set includes all individual student records.
4. Relationships :
- Definition : Relationships define how entities are related to each other. They
show the associations between different entities in the database.
- Example : A `Registration` relationship between `Student` and `Course`
indicates which students are enrolled in which courses.
5. Relationship Sets :
- Definition : A relationship set is a collection of similar relationships. It
represents how instances of different entities are associated with each other.
- Example : The `Registration` relationship set includes all student-course
enrollments.
6. Keys :
- Definition : Keys are attributes or sets of attributes that uniquely identify
instances of an entity. They are crucial for ensuring data integrity.
- Example : `StudentID` is a key attribute for the `Student` entity.
7. Cardinality :
- Definition : Cardinality defines the number of instances of one entity that can
or must be associated with each instance of another entity.
- Types :
- One-to-One (1:1) : Each instance of one entity is associated with exactly one
instance of another entity.
- One-to-Many (1:N) : Each instance of one entity is associated with multiple
instances of another entity.
- Many-to-Many (M:N) : Multiple instances of one entity are associated with
multiple instances of another entity.
8. ER Diagram :
- Definition : An ER diagram is a visual representation of the E-R model. It uses
symbols to represent entities, attributes, and relationships and their
interconnections.
- Example : A diagram showing `Student`, `Course`, and `Instructor` entities
with lines connecting them to represent relationships.
Need :
Database Design : The E-R model helps in designing databases by providing a
clear and structured way to visualize and organize data.
Communication : It serves as a communication tool between database
designers and stakeholders, ensuring that the database structure meets business
requirements.
The E-R model is fundamental in database design and helps in creating a
conceptual blueprint of the database, which can then be translated into a
physical database structure.
Ques 21. What are the Integrity Rules in DBMS?
Integrity rules in a Database Management System (DBMS) are constraints that
ensure the accuracy, consistency, and validity of data within the database. These
rules help maintain the quality and reliability of data throughout its lifecycle.
Key Integrity Rules :
1. Entity Integrity:
Definition : Ensures that each entity in a table is uniquely identifiable and that
no duplicate or null values exist in the primary key column.
Rule : Every table must have a primary key, and the values in the primary key
column(s) must be unique and not null.
Example : In a `Student` table, the `StudentID` column should have unique
values for each student and cannot be left empty.
2. Referential Integrity :
Definition : Maintains the consistency of relationships between tables by
ensuring that foreign key values in one table correspond to primary key values in
another table.
Rule : A foreign key must either be null or match a primary key value in the
referenced table.
Example : In an `Order` table, the `CustomerID` foreign key should match a
valid `CustomerID` in the `Customer` table.
3. Domain Integrity :
Definition : Ensures that data values in a column are within a defined range and
conform to specific data types and formats.
Rule : The data in each column must adhere to constraints such as data type,
length, and permissible values.
Example : A `Salary` column should only contain numeric values within a
reasonable range and adhere to the defined data type, such as `DECIMAL`.
4. User-Defined Integrity :
Definition : Custom constraints defined by users to enforce specific business
rules or requirements that are not covered by entity, referential, or domain
integrity.
Rule : These constraints are typically implemented using triggers, stored
procedures, or check constraints.
Example : A rule that a `Discount` percentage in a `Sales` table must be
between 0% and 50% can be enforced using a check constraint.
Need :
o Data Accuracy : Integrity rules ensure that the data is accurate and reliable,
reducing the likelihood of errors and inconsistencies.
o Data Consistency : They help maintain consistent relationships and valid
data across different tables and columns.
o Data Quality : By enforcing constraints, integrity rules contribute to high-
quality data that meets business requirements and standards.
Overall, integrity rules are crucial for maintaining the robustness and
trustworthiness of the database, ensuring that data remains correct and usable
for various applications and operations.
Need :
o Flexibility : Data independence provides flexibility in managing and evolving
the database structure without causing disruptions to existing systems or
user operations.
o Maintenance : It simplifies database maintenance and upgrades by
isolating changes to specific levels of the database schema.
o Scalability : Supports scalability by allowing modifications to the physical
storage or logical design without impacting application functionality.
2. Uniqueness :
Definition : Each row in a table must be uniquely identifiable, typically by a
primary key. No two rows should have identical values for the primary key.
Example : In a `Student` table, each row should have a unique `StudentID` to
differentiate between students.
Normalized to 1NF :
Need :
o Data Consistency : 1NF ensures that each cell contains a single value, which
helps in maintaining consistency and reducing redundancy.
o Simplified Queries : Tables in 1NF are easier to query and manage, as each
piece of data is stored in its own cell.
o Foundation for Further Normalization : 1NF is the first step in normalization,
setting the stage for further normalization processes like 2NF and 3NF, which
address more complex data organization issues.
1NF is fundamental for creating a structured and organized database schema that
supports efficient data retrieval and manipulation.
3NF is essential for ensuring that data is stored efficiently and that the database
design is robust, with minimal redundancy and improved integrity.
Summary :
o SQL Queries : Directly execute commands to manage and retrieve data.
o Database Clients : Use interfaces to interact with the database.
o APIs : Programmatically send and receive data from the database.
Example :
- In an `Enrollments` table, `StudentID` might be a foreign key referencing
`StudentID` in the `Students` table.
Example :
- In a `Users` table, an email address column might be a unique key to ensure no
duplicate email addresses.
Example :
- In the `Employees` table, if `EmployeeID` is chosen as the primary key,
`SocialSecurityNumber` becomes an alternate key.
Example :
- In an `OrderDetails` table, a combination of `OrderID` and `ProductID` might
serve as a composite key.
### 7. Super Key
Definition : A super key is a set of one or more columns that can uniquely identify
a record in a table. It includes the primary key and any additional attributes that
can uniquely identify records.
Characteristics : Contains Candidate Keys : All candidate keys are super keys,
but not all super keys are candidate keys.
Example :
- In a `Customers` table, `CustomerID` alone or `CustomerID` combined with
`PhoneNumber` can be super keys.
### Summary :
o Primary Key : Uniquely identifies each record, no NULLs allowed.
o Foreign Key : Links records between tables, may allow NULLs.
o Unique Key : Ensures uniqueness, can allow NULLs.
o Candidate Key : Possible keys for primary key selection, uniquely identify
records.
o Alternate Key : Candidate keys not selected as primary key.
o Composite Key : Combination of columns used to uniquely identify
records.
o Super Key : Any set of columns that can uniquely identify records.
Each type of key plays a critical role in maintaining data integrity and defining
relationships within a database.
2. Consistency :
- Definition : Guarantees that a transaction brings the database from one valid
state to another valid state, preserving all predefined rules, constraints, and
relationships.
- Example : If a database has a constraint that no two employees can have the
same employee ID, the consistency property ensures this constraint is
maintained before and after the transaction.
3. Isolation :
- Definition : Ensures that the operations of one transaction are isolated from
those of other concurrent transactions. Intermediate states of a transaction are
not visible to other transactions.
- Example : If two transactions are happening simultaneously, one transaction
should not see uncommitted changes made by the other until it is completed.
4. Durability :
- Definition : Once a transaction is committed, its effects are permanently
recorded in the database, even in the event of a system crash or failure.
- Example : After a transaction that updates a user’s email address is
committed, the new email address remains in the database even if the system
crashes immediately afterward.
Summary :
Transaction : A sequence of database operations executed as a single unit.
ACID Properties :
o Atomicity : All or nothing principle.
o Consistency : Database remains in a valid state before and after the
transaction.
o Isolation : Transactions operate independently of one another.
o Durability : Committed changes are permanent.