0% found this document useful (0 votes)
37 views

DBMS Top 30 Interview Question

This document contains interview questions and answers related to database normalization, keys, relationships, and other database concepts. It provides definitions and explanations of terms like primary keys, foreign keys, database normalization, functional dependencies, and more.

Uploaded by

Annonymous
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

DBMS Top 30 Interview Question

This document contains interview questions and answers related to database normalization, keys, relationships, and other database concepts. It provides definitions and explanations of terms like primary keys, foreign keys, database normalization, functional dependencies, and more.

Uploaded by

Annonymous
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

TOP 30

Interview Question

Created by- Topper World


Topperworld.in

Q 1. What is database normalization?

Ans: It is a process of analyzing the given relation schemas based on their


functional dependencies and primary keys to achieve the following desirable
properties:
1. Minimizing Redundancy
2. Minimizing the Insertion, Deletion, And Update Anomalies Relation
schemas that do not meet the properties are decomposed into smaller
relation schemas that could meet desirable properties.

Q 2. What is the difference between primary key and unique


constraints?

Ans:The primary key cannot have NULL value, the unique constraints can
have NULL values. There is only one primary key in a table, but there can be
multiple unique constrains.

Q 3. What are super, primary, candidate, and foreign keys?

Ans:
➢ A super key is a set of attributes of a relation schema upon which all
attributes of the schema are functionally dependent. No two rows can
have the same value of super key attributes.
➢ A Candidate key is a minimal superkey, i.e., no proper subset of
Candidate key attributes can be a superkey.
➢ A Primary Key is one of the candidate keys. One of the candidate keys is
selected as most important and becomes the primary key. There cannot
be more than one primary key in a table..

©Topperworld
➢ A Foreign key is a field (or collection of fields) in one table that uniquely
identifies a row of another table.

Q 4. What are the advantages of DBMS over traditional file-based


systems?

Ans: Database management systems were developed to handle the


following difficulties of typical File-processing systems supported by
conventional operating systems.
1. Data redundancy and inconsistency
2. Difficulty in accessing data
3. Data isolation – multiple files and formats
4. Integrity problems
5. Atomicity of updates
6. Concurrent access by multiple users
7. Security problems

Q 5. Why is the use of DBMS recommended? Explain by listing some


of its major advantages?

Ans : Some of the major advantages of DBMS are as follows:

➢ Controlled Redundancy: DBMS supports a mechanism to control the


redundancy of data inside the database by integrating all the data into a
single database and as data is stored in only one place, the duplicity of
data does not happen.
➢ Data Sharing: Sharing of data among multiple users simultaneously can
also be done in DBMS as the same database will be shared among all the

©Topperworld
users and by different application programs.
➢ Backup and Recovery Facility: DBMS minimizes the pain of creating the
backup of data again and again by providing a feature of ‘backup and
recovery’ which automatically creates the data backup and restores the
data whenever required.
➢ Enforcement of Integrity Constraints: Integrity Constraints are very
important to be enforced on the data so that the refined data after
putting some constraints are stored in the database and this is followed
by DBMS.
➢ Independence of Data: It simply means that you can change the
structure of the data without affecting the structure of any of the
application programs.

Q 6. What are the differences between DDL, DML, and DCL in SQL?

Ans: Following are some details of three :

➢ DDL stands for Data Definition Language. SQL queries like CREATE, ALTER,
DROP, TRUNCATE and RENAME come under this.
➢ DML stands for Data Manipulation Language. SQL queries like SELECT,
INSERT, DELETE and UPDATE come under this.
➢ DCL stands for Data Control Language. SQL queries like GRANT and REVOKE
come under this.

Q 7. What is Identity?
Ans: Identity (or AutoNumber) is a column that automatically generates numeric
values.

A start and increment value can be set, but most DBA leave these at 1.
A GUID column also generates numbers; the value of this cannot be controlled.
Identity/GUID columns do not need to be indexed.

©Topperworld
Q 8. What is a Trigger?

Ans :A Trigger is a code associated with insert, update or delete operations.


The code is executed automatically whenever the associated query is
executed on a table. Triggers can be useful to maintain integrity in the
database.

Q 9. What is a transaction? What are ACID properties?

Ans : A Database Transaction is a set of database operations that must be treated as


a whole, which means either all operations are executed or none of them.
An example can be a bank transaction from one account to another account. Either
both debit and credit operations must be executed or none of them.
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that
guarantee that database transactions are processed reliably.

Q 10. What are clustered and non-clustered Indexes?

Ans: Clustered indexes are the index according to which data is physically
stored on a disk.
Therefore, only one clustered index can be created on a given database
table.
Non-clustered indexes don’t define the physical ordering of data, but
logical ordering.
Typically, a tree is created whose leaf point to disk records. B-Tree or B+ tree
are used for this purpose.

©Topperworld
Q 11. What is a Live Lock?

Ans :Livelock situation can be defined as when two or more processes


continually repeat the same interaction in response to changes in the other
processes without doing any useful work.These processes are not in the
waiting state, and they are running concurrently. This is different from a
deadlock because in a deadlock all processes are in the waiting state.

Q 12. What is the purpose of normalization in DBMS?

Ans : Database normalization is the process of organizing the attributes of


the database to reduce or eliminate data redundancy (having the same data
but at different places).
Purpose of normalization:
⚫ It is used to remove duplicate data and database anomalies from the
relational table.
⚫ Normalization helps to reduce redundancy and complexity by examining
new data types used in the table.
⚫ It is helpful to divide the large database table into smaller tables and link
them using relationships.
⚫ It avoids duplicate data or no repeating groups into a table.
⚫ It reduces the chances for anomalies to occur in a database .

©Topperworld
Q 13. What is the main difference between UNION and UNION ALL?

Ans: UNION and UNION ALL are used to join the data from 2 or more tables
but UNION removes duplicate rows and picks the rows which are distinct
after combining the data from the tables whereas UNION ALL does not
remove the duplicate rows, it just picks all the data from the tables.

Q 14. What are the different levels of abstraction in the DBMS?

Ans :
◆ Physical Level: This is the lowest level of the data abstraction which
states how the data is stored in the database.
◆ Logical Level: This is the next level of the data abstraction which states
the type of the data and the relationship among the data that is stored in
the database.
◆ View Level: This is the highest level in the data abstraction which
shows/states only a part of the database.

Q 15. What is a functional dependency in the DBMS?

Ans: This is basically a constraint that is useful in describing the relationship


among the different attributes in a relation.
Example: If there is some relation ‘R1’ which has 2 attributes as Y and Z
then the functional dependency among these 2 attributes can be shown
as Y->Z which states that Z is functionally dependent on Y.

Q 16. What are the different types of relationships in the DBMS?

Ans : A Relationship in DBMS depicts an association between the tables.


Different types of relationships are:

©Topperworld
One-to-One: This basically states that there should be a one-to-one
relationship between the tables i.e. there should be one record in both the
tables.
One-to-Many: This states that there can be many relationships for one i.e. a
primary key table hold only one record which can have many, one, or none
records in the related table.
Many-to-Many: This states that both the tables can be related to many other
tables.

Q 17. What is conceptual design in dbms?

Ans : Conceptual design is the first stage in the database design process.
The goal at this stage is to design a database that is independent of
database software and physical details.
The output of this process is a conceptual data model that describes the
main data entities, attributes, relationships, and constraints of a given
problem domain.

Q 18. What is the main goal of RAID technology?

Ans : RAID stands for Redundant Array of Inexpensive (or sometimes


“Independent”)Disks.
RAID is a method of combining several hard disk drives into one logical unit
(two or more disks grouped together to appear as a single device to the host
system).
RAID technology was developed to address the fault-tolerance and

©Topperworld
performance limitations of conventional disk storage.
It can offer fault tolerance and higher throughput levels than a single hard
drive or group of independent hard drives.
While arrays were once considered complex and relatively specialized
storage solutions, today they are easy to use and essential for a broad
spectrum of client/server applications.

Q 19. Difference between primary key and unique key and why one
should use a unique key if it allows only one null ?

Ans :

Primary key:
⚫ Only one in a row(tuple).
⚫ Never allows null value(only key field).
⚫ Unique key identifier can not be null and must be unique.
Unique Key:
⚫ Can be more than one unique key in one row.
⚫ Unique key can have null values(only single null is allowed).
⚫ It can be a candidate key.
⚫ Unique key can be null and may not be unique.

Q 20.What is the difference between materialized and dynamic view?

Ans :

Materialized views
➢ Disk-based and are updated periodically based upon the query definition.
➢ A materialized table is created or updated infrequently and it must be
synchronized with its associated base tables.

©Topperworld
Dynamic views
➢ Virtual only and run the query definition each time they are accessed.
➢ A dynamic view may be created every time that a specific view is
requested by the user.

Q 21. What is embedded and dynamic SQL?

Ans:
Static or Embedded SQL
SQL statements in an application that do not change at runtime and, therefore, can be
hard-coded into the application.

Dynamic SQL
SQL statements that are constructed at runtime; for example, the
application may allow users to enter their own queries.
Dynamic SQL is a programming technique that enables you to buildSQL
statements dynamically at runtime.
You can create more general purpose, flexible applications by using dynamic
SQL because the full text of a SQL statement may be unknown at
compilation.

Static (embedded) SQL Dynamic (interactive) SQL

In static SQL how database will be


In dynamic SQL, how database will
accessed is predetermined in the
be accessed is determined at run
embedded SQL statement.
time.

It is more swift and efficient.


It is less swift and efficient.

©Topperworld
SQL statements are compiled at
SQL statements are compiled at run
compile time.
time.

Parsing, validation, optimization, and


Parsing, validation, optimization,
generation of application plan are
and generation of application plan
done at compile time.
are done at run time.

It is generally used for situations


It is generally used for situations
where data is distributed non-
where data is distributed uniformly.
uniformly.

EXECUTE IMMEDIATE, EXECUTE and


EXECUTE IMMEDIATE, EXECUTE and
PREPARE statements are not used.
PREPARE statements are used.

It is less flexible. It is more flexible.

Q 22. What is the difference between CHAR and VARCHAR?

Ans :
➢ CHAR and VARCHAR differ in storage and retrieval.
➢ CHAR column length is fixed while VARCHAR length is variable.
➢ The maximum no. of characters CHAR data type can hold is 255
characters while VARCHAR can hold up to 4000 characters.
➢ CHAR is 50% faster than VARCHAR.
➢ CHAR uses static memory allocation while VARCHAR uses dynamic
memory allocation.

©Topperworld
Q 23. There is a table where only one row is fully repeated. Write a
Query to find the Repeated row

Name Section

abc CS1

bcd CS2

abc CS1

Ans : In the above table, we can find duplicate row using below query.

SELECT name, section FROM tbl


GROUP BY name, section
HAVING COUNT(*) > 1

Q 24. Write a trigger to update Emp table such that, If an updation is


done in Dep table then salary of all employees of that department
should be incremented by some amount (updation)

Ans : Assuming Table name are Dept and Emp, trigger can be written as
follows:

©Topperworld
CREATE OR REPLACE TRIGGER update_trig
AFTER UPDATE ON Dept
FOR EACH ROW
DECLARE
CURSOR emp_cur IS SELECT * FROM Emp;
BEGIN
FOR i IN emp_cur LOOP
IF i.dept_no = :NEW.dept_no THEN
DBMS_OUTPUT.PUT_LINE(i.emp_no); -- for printing those
UPDATE Emp -- emp number which are
SET sal = i.sal + 100 -- updated
WHERE emp_no = i.emp_no;
END IF;
END LOOP;
END;

©Topperworld
Q 25. There is a table which contains two columns Student and
Marks, you need to find all the students, whose marks are greater
than average marks i.e. list of above-average students.
Ans :

SELECT student, marks


FROM table
WHERE marks > SELECT AVG(marks) from table;

Q 26. Name the Employee who has the third-highest salary using
sub queries.

Ans :
SELECT Emp1.Name
FROM Employee Emp1
WHERE 2 = (SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary
)

Q 27. What is a view in SQL? How to create a view?

Ans : A view is a virtual table based on the result-set of an SQL statement.


We can create it using create view syntax.

CREATE VIEW view_name AS


SELECT column_name(s)
FROM table_name
WHERE condition

©Topperworld
Q 28. What are the uses of view?

Ans :
1) Views can represent a subset of the data contained in a table;
consequently, a view can limit the degree of exposure of the underlying
tables to the outer world: a given user may have permission to query the
view, while denied access to the rest of the base table.
2) Views can join and simplify multiple tables into a single virtual table.
3) Views can act as aggregated tables, where the database engine
aggregates data (sum, average, etc.) and presents the calculated results
as part of the data.
4) Views can hide the complexity of data.
5) Views take very little space to store; the database contains only the
definition of a view, not a copy of all the data which it presents.
6) Depending on the SQL engine used, views can provide extra security.

Q 29. What is a stored procedure?

Ans : A stored procedure is like a function that contains a set of operations


compiled together. It contains a set of operations that are commonly used in
an application to do some common database tasks.

©Topperworld
Q 30. What is the difference between Trigger and Stored Procedure?

Ans :

Sr. Key Triggers Stored procedures


No.

1 Basic trigger is a stored Stored procedures are a


procedure that runs pieces of the code in
automatically when written in PL/SQL to do
various events happen some specific task
(eg update, insert, delete)

2 Running It can execute It can be invoked


Methodology automatically based on explicitly by the user
the events

3 Parameter It can not take input as It can take input as a


parameter parameter

4 Transaction we can't use transaction We can use transaction


statements statements inside a statements like begin
trigger transaction, commit
transaction, and rollback
inside a stored procedure

5 Return Triggers can not return Stored procedures can


values return values

©Topperworld
ABOUT US
At TopperWorld, we are on a mission to empower college students with the
knowledge, tools, and resources they need to succeed in their academic
journey and beyond.

➢ Our Vision

❖ Our vision is to create a world where every college student can easily
access high-quality educational content, connect with peers, and achieve
their academic goals.
❖ We believe that education should be accessible, affordable, and engaging,
and that's exactly what we strive to offer through our platform.

➢ Unleash Your Potential

❖ In an ever-evolving world, the pursuit of knowledge is essential.


TopperWorld serves as your virtual campus, where you can explore a
diverse array of online resources tailored to your specific college
curriculum.
❖ Whether you're studying science, arts, engineering, or any other discipline,
we've got you covered.
❖ Our platform hosts a vast library of e-books, quizzes, and interactive
study tools to ensure you have the best resources at your fingertips.

©Topperworld
➢ The TopperWorld Community

❖ Education is not just about textbooks and lectures; it's also about forming
connections and growing together.
❖ TopperWorld encourages you to engage with your fellow students, ask
questions, and share your knowledge.
❖ We believe that collaborative learning is the key to academic success.

➢ Start Your Journey with TopperWorld

❖ Your journey to becoming a top-performing college student begins with


TopperWorld.
❖ Join us today and experience a world of endless learning possibilities.
❖ Together, we'll help you reach your full academic potential and pave the
way for a brighter future.
❖ Join us on this exciting journey, and let's make academic success a reality
for every college student.

©Topperworld
“Unlock Your
Potential”
With- Topper World

Explore More

topperworld.in

DSA Tutorial C Tutorial C++ Tutorial

Java Tutorial Python Tutorial

Follow Us On
E-mail
[email protected]

You might also like