DBMS Interview Questions
DBMS Interview Questions
1. What is Database?
A database is an organized collection of data, stored and retrieved digitally from a remote or local
computer system. Databases can be vast and complex, and such databases are developed using fixed
design and modeling approaches.
2. What is DBMS?
DBMS stands for Database Management System. DBMS is a system software responsible for the
creation, retrieval, updation and management of the database. It ensures that our data is consistent,
organized and is easily accessible by serving as an interface between the database and its end users or
application softwares.
4. What is SQL?
SQL stands for Structured Query Language. It is the standard language for relational database
management systems. It is especially useful in handling organized data comprised of entities
(variables) and relations between different entities of the data.
RIGHT (OUTER) JOIN: Retrieves all the records/rows from the right and the matched records/rows
from the left table.
SELECT *
FROM Table_A A
RIGHT JOIN Table_B B
ON A.col = B.col;
FULL (OUTER) JOIN: Retrieves all the records where there is a match in either the left or right table.
SELECT *
FROM Table_A A
FULL JOIN Table_B B
ON A.col = B.col;
There are different types of indexes that can be created for different purposes:
Unique and Non-Unique Index:
Unique indexes are indexes that help maintain data integrity by ensuring that no two rows of data in a
table have identical key values. Once a unique index has been defined for a table, uniqueness is enforced
whenever keys are added or changed within the index.
CREATE UNIQUE INDEX myIndex
ON students (enroll_no);
Non-unique indexes, on the other hand, are not used to enforce constraints on the tables with which
they are associated. Instead, non-unique indexes are used solely to improve query performance by
maintaining a sorted order of data values that are used frequently.
18. What are some common clauses used with SELECT query in SQL?
Some common SQL clauses used in conjuction with a SELECT query are as follows:
WHERE clause in SQL is used to filter records that are necessary, based on specific conditions.
ORDER BY clause in SQL is used to sort the records based on some field(s) in ascending (ASC) or
descending order (DESC).
SELECT *
FROM myDB.students
WHERE graduation_year = 2019
ORDER BY studentID DESC;
GROUP BY clause in SQL is used to group records with identical data and can be used in conjuction
with some aggregation functions to produce summarized results from the database.
HAVING clause in SQL is used to filter records in combination with the GROUP BY clause. It is
different from WHERE, since WHERE clause cannot filter aggregated records.
SELECT COUNT(studentId), country
FROM myDB.students
WHERE country != "INDIA"
GROUP BY country
HAVING COUNT(studentID) > 5;
SELECT name FROM Students /* Fetch the union of queries with duplicates*/
UNION ALL
SELECT name FROM Contacts;
Relationships: Relations or links between entities that have something to do with each other. For
example - The employees table in a company's database can be associated with the salary table in the
same database.
As we can observe, the Books Issued field has more than one values per record and to convert it into
1NF, this has to be resolved into separate individual records for each book issued. Check the
following table in 1NF form –
Students Table (1st Normal Form)
Example 1 - Consider the Students Table in the above example. As we can observe, Students Table in
2NF form has a single candidate key Student_ID (primary key) that can uniquely identify all records in
the table. The field Salutation (non-prime attribute), however, depends on the Student Field rather than
the candidate key. Hence, the table is not in 3NF. To convert it into 3rd Normal Form, we will once
again partition the tables into two while specifying a new Foreign Key constraint to identify the
salutations for individual records in the Students table. The Primary Key constraint for the same will be
set on the Salutations table to identify each record uniquely.
Students Table (3rd Normal Form)
Books Table (3rd Normal Form)
Attribute is described as the properties or characteristics of an entity. For Example, Employee ID,
Employee Name, Age, etc., can be attributes of the entity Employee.
Relation is a two-dimensional table containing a number of rows and columns where every row
represents a record of the relation. Here, rows are also known as ‘Tuples’ and columns are known
as ‘Attributes’.
SELECT CURDATE();
63. What is a composite key?
When more than one column is used to define the primary key, it is called a composite key.
Primary Key: column or set of columns that identify a particular row in a table.
Super Key: single key or set of multiple keys that identifies rows of a table.
Candidate Key: A set of attributes which identify tuples of a table uniquely. It is essentially a super
key without repeated attributes.
Alternate Key: One or more columns of a table that collectively identify each of a table uniquely.
Foreign Key: A common column that defines the relationship between two tables. maintains data
integrity.
Compound Key: Consists of two more attributes that uniquely identify a record, even when the
column is not unique by itself
Composite Key: Primary key that has two or more attributes like {customer_id + mobile_number}
Surrogate Key: Created when there is no naturally available primary key for a table. provides a
unique identity to a row in the table.
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.