DBMS Interview Questions
DBMS Interview Questions
Answer:
DBMS stands for Database Management System, is a set of applications or programs
that enable users to create and maintain a database. DBMS provides a tool or an
interface for performing various operations such as inserting, deleting, updating, etc. into
a database. It is software that enables the storage of data more compactly and securely
as compared to a le-based system. A DBMS system helps a user to overcome problems
like data inconsistency, data redundancy, etc. in a database and makes it more
convenient and organized to use it.
Answer:
RDBMS stands for Relational Database Management System and was introduced in
the 1970s to access and store data more e ciently than DBMS. RDBMS stores data in
the form of tables as compared to DBMS which stores data as les. Storing data as rows
and columns makes it easier to locate speci c values in the database and makes it more
e cient as compared to DBMS.
Examples of popular RDBMS systems are MySQL, Oracle DB, etc.
Answer:
A Database is an organized, consistent, and logical collection of data that can easily be
updated, accessed, and managed. Database mostly contains sets of tables or objects
(anything created using create command is a database object) which consist of records
and elds. A tuple or a row represents a single entry in a table. An attribute or a column
represents the basic units of data storage, which contain information about a particular
aspect of the table.
Q4. Mention the issues with traditional le-based systems that make DBMS a better
choice?
Answer:
The absence of indexing in a traditional le-based system leaves us with the only option
of scanning the full page and hence making the access of content tedious and super
slow. The other issue is redundancy and inconsistency as les have many duplicate and
redundant data and changing one of them makes all of them inconsistent. Accessing data
is harder in traditional le-based systems because data is unorganized in them.
Another issue is the lack of concurrency control, which leads to one operation locking the
entire page, as compared to DBMS where multiple operations can work on a single le
simultaneously.
Integrity check, data isolation, atomicity, security, etc. are some other issues with
traditional le-based systems for which DBMSs have provided some good solutions.
ffi
fi
fi
fi
fi
fi
fi
ffi
fi
fi
fi
fi
Q5. Are NULL values in a database the same as that of blank space or zero?
Answer:
No, a NULL value is very di erent from that of zero and blank space as it represents a
value that is assigned, unknown, unavailable, or not applicable as compared to blank
space which represents a character and zero represents a number.
Example: NULL value in “number_of_courses” taken by a student represents that its value
is unknown whereas 0 in it means that the student hasn’t taken any courses
.
Answer:
The process of hiding irrelevant details from users is known as data abstraction. Data
abstraction can be divided into 3 levels:
• Physical Level: it is the lowest level and is managed by DBMS. This level consists
of data storage descriptions and the details of this level are typically hidden from
system admins, developers, and users.
• Conceptual or Logical level: it is the level on which developers and system
admins work and it determines what data is stored in the database and what is the
relationship between the data points.
• External or View level: it is the level that describes only part of the database and
hides the details of the table schema and its physical storage from the users. The
result of a query is an example of View level data abstraction. A view is a virtual
table created by selecting elds from one or more tables present in the database.
answer:
• Intension: Intension or popularly known as database schema is used to de ne the
description of the database and is speci ed during the design of the database and
mostly remains unchanged.
• Extension: Extension on the other hand is the measure of the number of tuples
present in the database at any given point in time. The extension of a database is
also referred to as the snapshot of the database and its value keeps changing as
and when the tuples are created, updated, or destroyed in a database.
Q8. Explain the di erence between the DELETE and TRUNCATE command in a
DBMS.
Answer:
DELETE command: this command is needed to delete rows from a table based on the
condition provided by the WHERE clause.
TRUNCATE command: this command is needed to remove complete data from a table
in a database. It is like a DELETE command which has no WHERE clause.
ff
ff
ff
fi
ff
fi
fi
Q9. What is a lock? Explain the major di erence between a shared lock and an
exclusive lock during a transaction in a database.
Answer:
A database lock is a mechanism to protect a shared piece of data from getting updated
by two or more database users at the same time. When a single database user or session
has acquired a lock then no other database user or session can modify that data until the
lock is released.
• Shared Lock: A shared lock is required for reading a data item and many
transactions may hold a lock on the same data item in a shared lock. Multiple
transactions are allowed to read the data items in a shared lock.
• Exclusive lock: An exclusive lock is a lock on any transaction that is about to
perform a write operation. This type of lock doesn’t allow more than one
transaction and hence prevents any inconsistency in the database.
Answer:
Normalization is a process of reducing redundancy by organizing the data into multiple
tables. Normalization leads to better usage of disk spaces and makes it easier to maintain
the integrity of the database.
Denormalization is the reverse process of normalization as it combines the tables which
have been normalized into a single table so that data retrieval becomes faster. JOIN
operation allows us to create a denormalized form of the data by reversing the
normalization.
Q11. Explain the di erence between a 2-tier and 3-tier architecture in a DBMS.
Answer:
The 2-tier architecture refers to the client-server architecture in which applications at the
client end directly communicate with the database at the server end without any
middleware involved.
The 3-tier architecture contains another layer between the client and the server to
provide GUI to the users and make the system much more secure and accessible. In this
type of architecture, the application present on the client end interacts with an application
on the server end which further communicates with the database system.
Answer:
• Redundancy control
• Restriction for unauthorized access
• Provides multiple user interfaces
• Provides backup and recovery
• Enforces integrity constraints
• Ensure data consistency
• Easy accessibility
• Easy data extraction and data processing due to the use of queries
ff
ff
Q13. What is a checkpoint in DBMS?
Answer:
The Checkpoint is a type of mechanism where all the previous logs are removed from the
system and permanently stored in the storage disk.
Answer:
The transparent DBMS is a type of DBMS which keeps its physical structure hidden from
users. Physical structure or physical storage structure implies to the memory manager of
the DBMS, and it describes how the data stored on disk.
Answer:
Data De nition Language (DDL) is a standard for commands which de nes the di erent
structures in a database. Most commonly DDL statements are CREATE, ALTER, and
DROP. These commands are used for updating data into the database.
Answer:
Data Manipulation Language (DML) is a language that enables the user to access or
manipulate data as organized by the appropriate data model. For example- SELECT,
UPDATE, INSERT, DELETE.
There is two type of DML:
Procedural DML or Low level DML: It requires a user to specify what data are needed
and how to get those data.
Non-Procedural DML or High level DML:It requires a user to specify what data are
needed without specifying how to get those data.
Answer:
The term query optimization speci es an e cient execution plan for evaluating a query
that has the least estimated cost. The concept of query optimization came into the frame
when there were a number of methods, and algorithms existed for the same task then the
question arose that which one is more e cient and the process of determining the
e cient way is known as query optimization.
Answer:
ffi
fi
fi
fi
ffi
ffi
fi
ff
Structured Query Language is the core of the relational database which is used for
accessing and managing the databases. This language is used to manipulate and retrieve
data from a structured data format in the form of tables and holds relationships between
those tables. So, in layman terms, you can use SQL to communicate with the database.
Answer:
A subquery is a query inside another query where a query is de ned to retrieve data or
information back from the database. In a subquery, the outer query is called as the main
query whereas the inner query is called subquery. Subqueries are always executed rst
and the result of the subquery is passed on to the main query. It can be nested inside a
SELECT, UPDATE or any other query. A subquery can also use any comparison operators
such as >,< or =.
Answer:
UNION UNION ALL
Combines the Combines the
result of two or result set of two
more SELECT or more
statements SELECT
consisting of statements
distinct values consisting of
duplicate values
Syntax: UNION Syntax: UNION
ALL
Has low Has better
performance performance
than UNION than UNION, as
ALL, as duplicate rows
duplicate rows need not have
need to be to be removed.
removed.
Answer:
CLAUSE in SQL is used to limit the result set by mentioning a condition to the query. So,
you can use a CLAUSE to lter rows from the entire set of records.
Example: WHERE HAVING clause.
Answer:
You can perform pattern matching in SQL by using the LIKE operator. With the LIKE
operator, you can use the following symbols:
1. %(Percentage sign) – To match zero or more characters.
Answer:
This function returns the string with the rst letter in uppercase and the rest of the letters
in lowercase.
Syntax: INITCAP(‘string’)
Q25. What are joins in SQL and what are the di erent types of joins?
Answer:
A JOIN clause is used to combine rows from two or more tables, based on a related
column between them. It is used to merge two tables or retrieve data from there. There
are 4 joins in SQL namely:
• Inner Join
• Right Join
• Left Join
• Full Join
Q26. Write a query to create a duplicate table with and without data present?
Answer:
CREATE TABLE DuplicateCustomer AS SELECT * FROM Customers;
fi
ff
Q27. Mention a query to calculate the even and odd records from a table
Answer:
Even records
SELECT CustomerID FROM (SELECT rowno, CustomerID from Customers) where
mod(rowno,2)=0;
Odd records
SELECT CustomerID FROM (SELECT rowno, CustomerID from Customers) where
mod(rowno,2)=1;
Note: To remove duplicate rows from a table, you have to initially select the duplicate
rows from the table without using the DISTINCT keyword.
Answer:
SELECT Email FROM Customers WHERE NOT REGEXP_LIKE(Email, &lsquo;[A-
Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}&rsquo;, &lsquo;i&rsquo;);
Answer:
An extension of an entity type is speci ed as a collection of entities of a particular entity
type that are grouped into an entity set.
Answer:
The Join operation is one of the most useful activities in relational algebra. It is most
commonly used way to combine information from two or more relations. A Join is always
performed on the basis of the same or related column. Most complex queries of SQL
involve JOIN command.
Answer:
A stored procedure is a group of SQL statements that have been created and stored in
the database. The stored procedure increases the reusability as here the code or the
procedure is stored into the system and used again and again that makes the work easy,
takes less time in processing and decreases the complexity of the system. So, if you have
fi
a code which you need to use again and again then save that code and call that code
whenever it is required.
Answer:
You have to use Structured Query Language (SQL) to communicate with the RDBMS.
Using queries of SQL, we can give the input to the database and then after processing of
the queries database will provide us the required output.
Answer:
The 3-Tier architecture contains another layer between the client and server. Introduction
of 3-tier architecture is for the ease of the users as it provides the GUI, which, make the
system secure and much more accessible. In this architecture, the application on the
client-end interacts with an application on the server which further communicates with
the database system.
Answer:
• BCNF: BCNF stands for Boyce-Codd Normal Form and is an advanced form of
3NF. It is also referred to as 3.5NF for the same reason. A table to be in its BCNF
normal form should satisfy the following conditions:
• The table should be in its 3NF i.e. satisfy all the conditions of 3NF.
• For every functional dependency of any attribute A on B
(A->B), A should be the super key of the table. It simply implies that A can’t be a
non-prime attribute if B is a prime attribute.
Answer;
The candidate key represents a set of properties that can uniquely identify a table. Each
table may have multiple candidate keys. One key amongst all candidate keys can be
chosen as a primary key. In the below example since studentId and rstName can be
considered as a Candidate Key since they can uniquely identify every tuple.
Answer:
The super key de nes a set of attributes that can uniquely identify a tuple. Candidate key
and primary key are subsets of the super key, in other words, the super key is their
superset.
Answer:
fi
fi
The primary key de nes a set of attributes that are used to uniquely identify every tuple.
In the below example studentId and rstName are candidate keys and any one of them
can be chosen as a Primary Key. In the given example studentId is chosen as the primary
key for the student table.
Answer:
The unique key is very similar to the primary key except that primary keys don’t allow
NULL values in the column but unique keys allow them. So essentially unique keys are
primary keys with NULL values.
Answer:
All the candidate keys which are not chosen as primary keys are considered as alternate
Keys. In the below example, rstname and lastname are alternate keys in the database.
Answer:
The foreign key de nes an attribute that can only take the values present in one table
common to the attribute present in another table. In the below example courseId from the
Student table is a foreign key to the Course table, as both, the tables contain courseId as
one of their attributes.
Answer:
A composite key refers to a combination of two or more columns that can uniquely
identify each tuple in a table. In the below example the studentId and rstname can be
grouped to uniquely identify every tuple in the table.
——————————————————————
TEST YOURSELF
Q5. Which of the following contains information about the data stored in a DBMS?
1. Meta data
2. Directory
3. Sub data
4. Warehouse
————————————————————
Answers:
1. Rectangle
2. Tuple
3. Open database connectivity
4. one teacher many students
5. meta data
6. Database administrator
7. Transaction control language
8. Create information table in the Database
9. Candidate key
10. The size of the disk storage device