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

DBMS

The document provides an overview of Database Management Systems (DBMS), including definitions, advantages, and key concepts such as databases, database systems, and normalization. It covers various topics including ACID properties, data models, relational databases, query languages, and the importance of data abstraction and functional dependencies. Additionally, it discusses normalization forms and the purpose of normalization in reducing data redundancy and improving database efficiency.

Uploaded by

Deb Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DBMS

The document provides an overview of Database Management Systems (DBMS), including definitions, advantages, and key concepts such as databases, database systems, and normalization. It covers various topics including ACID properties, data models, relational databases, query languages, and the importance of data abstraction and functional dependencies. Additionally, it discusses normalization forms and the purpose of normalization in reducing data redundancy and improving database efficiency.

Uploaded by

Deb Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

DBMS Interview Questions

1. What is DBMS?
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 file-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.
Some popular DBMS system - File systems, XML, Windows Registry etc.

2. What is a Database?
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 fields. 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. DBMS extracts data from a database in the form of queries given by the
user.

3. What is a database system?


The collection of database and DBMS software together is known as a database system. Through the
database system, we can perform many activities such as -
 The data can be stored in the database with ease, and there are no issues of data redundancy and
data inconsistency.
 The data will be extracted from the database using DBMS software whenever required. So, the
combination of database and DBMS software enables one to store, retrieve and access data with
considerate accuracy and security.

1. What are the advantages of DBMS over traditional file-based systems?


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
4. What are the advantages of DBMS?
 Data Sharing: Data from a single database can be simultaneously shared by multiple users. Such
sharing also enables end-users to react to changes quickly in the database environment.
 Integrity constraints: The existence of such constraints allows storing of data in an organized and
refined manner.
 Controlling redundancy in a database: Eliminates redundancy in a database by providing a
mechanism that integrates all the data in a single database.
 Data Independence: This allows changing the data structure without altering the composition of
any of the executing application programs.
 Provides backup and recovery facility: It can be configured to automatically create the backup of
the data and restore the data in the database whenever required.
 Data Security: DBMS provides the necessary tools to make the storage and transfer of data more
reliable and secure. Authentication (the process of giving restricted access to a user) and encryption
(encrypting sensitive data such as OTP, credit card information, etc.) are some popular tools used to
secure data in a DBMS.

5. What is a checkpoint in DBMS?


The Checkpoint is a type of mechanism where all the previous logs are removed from the system and
permanently stored in the storage disk.
There are two ways which can help the DBMS in recovering and maintaining the ACID properties, and they
are- maintaining the log of each transaction and maintaining shadow pages. So, when it comes to log-
based recovery system, checkpoints come into existence. Checkpoints are those points to which the
database engine can recover after a crash as a specified minimal point from where the transaction log
record can be used to recover all the committed data up to the point of the crash.

6. When does checkpoint occur in DBMS?


A checkpoint is like a snapshot of the DBMS state. Using checkpoints, the DBMS can reduce the amount of
work to be done during a restart in the event of subsequent crashes. Checkpoints are used for the recovery
of the database after the system crash. Checkpoints are used in the log-based recovery system. When due
to a system crash we need to restart the system then at that point we use checkpoints. So that, we don't
have to perform the transactions from the very starting.

7. What do you mean by transparent DBMS?


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.

6. What is meant by ACID properties in DBMS?


ACID stands for Atomicity, Consistency, Isolation, and Durability in a DBMS these are those properties that
ensure a safe and secure way of sharing data among multiple users.

Atomicity: This property reflects the concept of either executing the whole query or executing nothing at
all, which implies that if an update occurs in a database, then that update should either be reflected in the
whole database or should not be reflected at all.
Consistency: This property ensures that the data remains consistent before and after a transaction in a
database.
Isolation: This property ensures that each transaction is occurring independently of the others. This implies
that the state of an ongoing transaction doesn’t affect the state of another ongoing transaction.
Durability: This property ensures that the data is not lost in cases of a system failure or restart and is
present in the same state as it was before the system failure or restart.

11) What do you understand by Data Model?


The Data model is specified as a collection of conceptual tools for describing data, data relationships, data
semantics and constraints. These models are used to describe the relationship between the entities and
their attributes. There is the number of data models:
o Hierarchical data model
o Network model
o Relational model
o Entity-Relationship model and so on.

9. What is RDBMS?
RDBMS stands for Relational Database Management System and was introduced to access and store data
more efficiently than DBMS. RDBMS stores data in the form of tables as compared to DBMS which stores
data as files. Storing data as rows and columns makes it easier to locate specific values in the database and
makes it more efficient as compared to DBMS.
Examples of popular RDBMS systems are MySQL, Oracle DB, etc.

50) How do you communicate with an RDBMS?


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.

12) Define a Relation Schema and a Relation.


A Relation Schema is specified as a set of attributes. It is also known as table schema. It defines what the
name of the table is. Relation schema is known as the blueprint with the help of which we can explain that
how the data is organized into tables. This blueprint contains no data. A relation is specified as a set of
tuples. A relation is the set of related attributes with identifying key attributes

13) What is a degree of Relation?


The degree of relation is a number of attributes of its relation schema. A degree of relation is also known as
Cardinality it is defined as the number of occurrences of one entity which is connected to the number of
occurrences of other entity. There are three degree of relation they are one-to-one (1:1), one-to-
many(1:M), many-to-one(M:M).

14) What is the Relationship?


The Relationship is defined as an association among two or more entities. There are three types of
relationships in DBMS-
One to One Relationship: This type of relationship is applied when a particular row in table X is linked to a
singular row in table Y.

One to Many Relationship: This type of relationship is applied when a single row in table X is related to
many rows in table Y.

Many to Many Relationship: This type of relationship is applied when multiple rows in table X can be
linked to multiple rows in table Y.

16) What is data abstraction in DBMS?


Data abstraction in DBMS is a process of hiding irrelevant details from users. Because database systems are
made of complex data structures so, it makes accessible the user interaction with the database.
9. Explain different levels of data abstraction in a DBMS.
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. It describes how data are stored. 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. It describes what
data are stored in the database and what the relationship among those data is.
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 fields from one or more tables present in the
database.

10. How many types of database languages are?


There are four types of database languages:
Data Definition Language (DDL) : These commands are used for updating the data that’s why they are
known as Data Definition Language. e.g., CREATE, ALTER, DROP, TRUNCATE, RENAME, etc.
Data Manipulation Language (DML) : These commands are used for the manipulation of already updated
data that's why they are the part of Data Manipulation Language. e.g., SELECT, UPDATE, INSERT, DELETE,
etc.
o Procedural DML or Low level DML: It requires a user to specify what data are needed and how to
get those data.
o Non-Procedural DML or High level DML: It requires a user to specify what data are needed without
specifying how to get those data.
Data Control Language (DCL) : These commands are used for giving and removing the user access on the
database. So, they are the part of Data Control Language. e.g., GRANT and REVOKE.
Transaction Control Language (TCL) : These are the commands used for managing transactions in the
database. TCL is used for managing the changes made by DML. e.g., COMMIT, ROLLBACK, and SAVEPOINT

20) Explain the functionality of DML Compiler.


The DML Compiler translates DML statements in a query language that the query evaluation engine can
understand. DML Compiler is required because the DML is the family of syntax element which is very
similar to the other programming language which requires compilation. So, it is essential to compile the
code in the language which query evaluation engine can understand and then work on those queries with
proper output.

21) What is Relational Algebra?


Relational Algebra is a Procedural Query Language which contains a set of operations that take one or two
relations as input and produce a new relationship. Relational algebra is the basic set of operations for the
relational model. The decisive point of relational algebra is that it is similar to the algebra which operates
on the number.
There are few fundamental operations of relational algebra:
 select
 project
 set difference
 union
 rename, etc.

8. What are the unary operations in Relational Algebra?


PROJECTION and SELECTION are the unary operations in relational algebra. Unary operations are those
operations which use single operands. Unary operations are SELECTION, PROJECTION, and RENAME.
As in SELECTION relational operators are used for example: =, <=, >= etc.

22) What is Relational Calculus?


Relational Calculus is a Non-procedural Query Language which uses mathematical predicate calculus
instead of algebra. Relational calculus doesn't work on mathematics fundamentals such as algebra,
differential, integration, etc. That's why it is also known as predicate calculus.
There are two types of relational calculus:
 Tuple relational calculus
 Domain relational calculus

23) What do you understand by query optimization?


The term query optimization specifies an efficient 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
efficient and the process of determining the efficient way is known as query optimization.
There are many benefits of query optimization:
 It reduces the time and space complexity.
 More queries can be performed as due to optimization every query comparatively takes less time.
 User satisfaction as it will provide output fast

27) What is functional Dependency?


Functional Dependency is the starting point of normalization. It exists when a relation between two
attributes allows you to determine the corresponding attribute's value uniquely. The functional
dependency is also known as database dependency and defines as the relationship which occurs when one
attribute in a relation uniquely determines another attribute. It is written as A->B which means B is
functionally dependent on A.
27) What is Transitive Dependency?
A transitive dependency is a constraint that can only occur in a relation of three or more attributes.
Example: Consider a relation “A1” having attributes X, Y and Z. Now, X->Z is said to hold transitive
dependency, only if the following functional dependencies holds true:
 X -> Y
 Y doesn’t ->X
 Y -> Z

25) What is normalization?


Normalization is a process of analysing the given relation schemas according to their functional
dependencies. It is used to minimize redundancy and also used to minimize insertion, deletion and update
distractions. Normalization is considered as an essential process as it is used to avoid data redundancy,
insertion anomaly, updation anomaly, deletion anomaly.

26) What is Denormalization?


Denormalization is the process of boosting up database performance and adding of redundant data which
helps to get rid of complex data. Denormalization is a part of database optimization technique. This
process is used to avoid the use of complex and costly joins. Denormalization doesn't refer to the thought
of not to normalize instead of that denormalization takes place after normalization. In this process, firstly
the redundancy of the data will be removed using normalization process than through denormalization
process we will add redundant data as per the requirement so that we can easily avoid the costly joins.

41) What is 1NF?


1NF is the First Normal Form. A table to be in its first normal form should satisfy the following conditions:
 Every column must have a single value and should be atomic.
 Duplicate columns from the same table should be removed.
 Separate tables should be created for each group of related data and each row should be identified
with a unique column.

42) What is 2NF?


2NF is the Second Normal Form. A table to be in its second normal form should satisfy the following
conditions:
 The table should be in its 1NF i.e., satisfy all the conditions of 1NF.
 Every non-prime attribute of the table should be fully functionally dependent on the primary key
i.e., every non-key attribute should be dependent on the primary key in such a way that if any key
element is deleted then even the non_key element will be saved in the database.

43) What is 3NF?


3NF stands for Third Normal Form. A table to be in its second normal form should satisfy the following
conditions:
 The table should be in its 2NF i.e., satisfy all the conditions of 2NF.
 There is no transitive functional dependency of one attribute on any attribute in the same table.

44) What is 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.

23. What is the purpose of normalization in DBMS?


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.

28) What is the E-R model?


E-R model is a short name for the Entity-Relationship model. This model is based on the real world. It
contains necessary objects (known as entities) and the relationship among these objects. Here the primary
objects are the entity, attribute of that entity, relationship set, an attribute of that relationship set can be
mapped in the form of E-R diagram.
In E-R diagram, entities are represented by rectangles, relationships are represented by diamonds,
attributes are the characteristics of entities and represented by ellipses, and data flow is represented
through a straight line.

29) What is an entity?


The Entity is a set of attributes in a database. An entity can be a real-world object which physically exists in
this world. All the entities have their attribute which in the real world considered as the characteristics of
the object.
For example: In the employee database of a company, the employee, department, and the designation can
be considered as the entities. These entities have some characteristics which will be the attributes of the
corresponding entity.

30) What is an Entity type?


An entity type is specified as a collection of entities, having the same attributes. Entity type typically
corresponds to one or several related tables in the database. A characteristic or trait which defines or
uniquely identifies the entity is called entity type.
For example, a student has student_id, department, and course as its characteristics.

31) What is an Entity set?


The entity set specifies the collection of all entities of a particular entity type in the database. An entity set
is known as the set of all the entities which share the same properties.
For example, a set of people, a set of students, a set of companies, etc.

33) What is Weak Entity set?


An entity set that doesn't have sufficient attributes to form a primary key is referred to as a weak entity
set. The member of a weak entity set is known as a subordinate entity. Weak entity set does not have a
primary key, but we need a mean to differentiate among all those entries in the entity set that depend on
one particular strong entity set.

34) What is an attribute?


An attribute refers to a database component. It is used to describe the property of an entity. An attribute
can be defined as the characteristics of the entity. Entities can be uniquely identified using the attributes.
Attributes represent the instances in the row of the database.
For example: If a student is an entity in the table, then age will be the attribute of that student.

15. What is a transaction?


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.

36) What do you mean by extension and intension?


Intension: Intension or popularly known as database schema is used to define the description of the
database and is specified 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.

38) What is Data Independence?


Data independence specifies that "the application is independent of the storage structure and access
strategy of data." It makes you able to modify the schema definition at one level without altering the
schema definition in the next higher level.
There are two types of Data Independence:
Physical Data Independence: Physical data is the data stored in the database. It is in the bit-format.
Modification in physical level should not affect the logical level.
For example: If we want to manipulate the data inside any table that should not change the format of the
table.
Logical Data Independence: Logical data in the data about the database. It basically defines the structure.
Such as tables stored in the database. Modification in logical level should not affect the view level. Logical
Data Independence is more difficult to achieve.
For example: If we need to modify the format of any table, that modification should not affect the data
inside it.

40) What is Join?


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.
There are following types of join:
o Inner joins: Inner join is of 3 categories. They are:
o Theta join
o Natural join
o Equi join

o Outer joins: Outer join have three types. They are:


o Left outer join
o Right outer join
o Full outer join

13. Explain the difference between the DELETE, TRUNCATE and DROP command.
DELETE command: this command is a DML Command which is used to delete rows from a table based on
the condition provided by the WHERE clause.
 It deletes only the rows which are specified by the WHERE clause.
 It can be rolled back if required.
 It maintains a log to lock the row of the table before deleting it and hence it’s slow.
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.
 It removes complete data from a table in a database.
 It can be rolled back even if required. (TRUNCATE can be rolled back in some databases depending
on their version but it can be tricky and can lead to data loss).
 It doesn’t maintain a log and deletes the whole table at once and hence it’s fast.
DROP command: this command is a DDL command which is used to drop/delete the existing table,
database, index, or view from the database.
18. Explain the difference between a 2-tier and 3-tier architecture in a DBMS.
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.
Example – Contact Management System created using MS-Access or Railway Reservation System, etc.
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.
Example – Designing registration form which contains a text box, label, button or a large website on the
Internet, etc.

12. What is concurrency control?


This is a process of managing simultaneous operations in a database so that database integrity is not
compromised. The following are the two approaches involved in concurrency control:
 Optimistic approach – Involves versioning
 Pessimistic approach – Involves locking

51) What is the difference between a shared lock and exclusive lock?
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: Shared lock is required for reading a data item. In the shared lock, many transactions may
hold a lock on the same data item. When more than one transaction is allowed to read the data items then
that is known as the shared lock.
Exclusive lock: When any transaction is about to perform the write operation, then the lock on the data
item is an exclusive lock. Because, if we allow more than one transaction then that will lead to the
inconsistency in the database.

20. What is a Live Lock?


Live lock 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.

24. What do you understand by Proactive, Retroactive and Simultaneous Update?


Proactive Update: These updates are applied to the database before it becomes effective in the real-world
environment.
Retroactive Update: These retroactive updates are applied to a database after it becomes effective in the
real-world environment.
Simultaneous Update: These updates are applied to the database at the same instance of time as it
becomes effective in a real-world environment.

34. Explain what is a deadlock and mention how it can be resolved?


Deadlock is a situation which occurs when two transactions wait on a resource which is locked or other
transaction holds. Deadlocks can be prevented by making all the transactions acquire all the locks at the
same instance of time. So, once deadlock occurs, the only way to cure is to abort one of the transactions
and remove the partially completed work.

52) Explain different types of keys in a database.


Candidate Key: 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.
Super Key: The super key defines 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.
Primary Key: The primary key defines a set of attributes that are used to uniquely identify every tuple.
Unique Key: The unique key is very similar to the primary key except that primary key don’t allow NULL
values in the column but unique keys allow them. So essentially unique keys are primary keys with NULL
values.
Alternate Key: All the candidate keys which are not chosen as primary keys are considered as alternate
Keys.
Foreign Key: The foreign key defines an attribute that can only take the values present in one table
common to the attribute present in another table.
Composite Key: A composite key refers to a combination of two or more columns that can uniquely
identify each tuple in a table.

3. What is the difference between primary key and unique constraints/key?


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.

26. Explain the concepts of a Primary key and Foreign Key.


Primary Key is used to uniquely identify the records in a database table while Foreign Key is mainly used to
link two or more tables together, as this is a particular field(s) in one of the database tables which are the
primary key of some other table.
Example: There are 2 tables – Employee and Department. Both have one common field/column as
‘ID’ where ID is the primary key of the Employee table while this is the foreign key for
the Department table.
7. Are NULL values in a database the same as that of blank space or zero?
No, a NULL value is very different 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.

8. What is Data Warehousing?


The process of collecting, extracting, transforming, and loading data from multiple sources and storing
them in one database is known as data warehousing. A data warehouse can be considered as a central
repository where data flows from transactional systems and other relational databases and is used for data
analytics. A data warehouse comprises a wide variety of an organization’s historical data that supports the
decision-making process in an organization.

22. What is a query?


A query with respect to DBMS relates to user commands that are used to interact with a data base.

7. What is the difference between having and where clause?


HAVING is used to specify a condition for a group or an aggregate function used in a select statement. The
WHERE clause selects before grouping. The HAVING clause selects rows after grouping. Unlike the HAVING
clause, the WHERE clause cannot contain aggregate functions.

9. What is Identity?
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.

10.What is a view in SQL? How to create a view?


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

11.What are the uses of view?


 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.
 Views can join and simplify multiple tables into a single virtual table.
 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.
 Views can hide the complexity of data.
 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.
 Depending on the SQL engine used, views can provide extra security.

Q. What’s the difference between materialized and dynamic view?


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.
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.

12. What is a Trigger?


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.

46) What is stored procedure?


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 a code which you need to use again and again then save that code and call
that code whenever it is required.

14. What is the difference between Trigger and Stored Procedure?


Unlike Stored Procedures, Triggers cannot be called directly. They can only be associated with queries.

16. What are indexes?


A database index is a data structure that improves the speed of data retrieval operations on a database
table at the cost of additional writes and the use of more storage space to maintain the extra copy of
data. Data can be stored only in one order on a disk. To support faster access according to different values,
faster search like binary search for different values is desired, For this purpose, indexes are created on
tables. These indexes need extra space on the disk, but they allow faster search according to different
frequently searched values.
17. What are clustered and non-clustered Indexes?
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 is used for this purpose.

64. What is a dependency graph?


A dependency graph is a diagram that is used to portray the connections between database elements.

54. What is the main goal of RAID technology?


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 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.

87. What are serial, non-serial schedule?


A schedule S is serial if, for every transaction T participating in the schedule, all the operations of T is
executed consecutively in the schedule, otherwise, the schedule is called non-serial schedule.

88. What are conflict serializable schedules?


A schedule S of n transactions is serializable if it is equivalent to some serial schedule of the same n
transactions.

89. What is view serializable?


A schedule is said to be view serializable if it is view equivalent with some serial schedule.

93. What is a Phantom Deadlock?


In distributed deadlock detection, the delay in propagating local information might cause the deadlock
detection algorithms to identify deadlocks that do not really exist. Such situations are called phantom
deadlocks and they lead to unnecessary aborts.

21. What is QBE?


Query-by-example represents a visual/graphical approach for accessing information in a database through
the use of query templates called skeleton tables. It is used by entering example values directly into a
query template to represent what is to be achieved. QBE is used by many database systems for personal
computers. QBE is a very powerful facility that gives the user the capability to access the information a user
wants without the knowledge of any programming language. Queries in QBE are expressed by skeleton
tables. QBE has two distinct features: QBE has the two-dimensional syntax: Queries look like tables.

27. What do you understand by cursor? Mention the different types of cursors.
A cursor is a database object which helps in manipulating data, row by row and represents a result set. The
types of cursors are as follows:
Implicit cursor: This type of cursor is declared automatically as soon as the execution of SQL takes place.
Here, the user is not indicated about the declaration of the cursor.
Explicit cursor: This type of cursor is defined by the PL/ SQL, as it handles a query in more than a single
row.

28. Explain the terms specialization and generalization


Specialization: Specialization is a process of defining a set of subclasses of the entity type. Here, each
subclass will contain all the attributes and relationships of the parent entity. Apart from this, the subclasses
may contain additional attributes and relationships specific to itself.
Generalization: Generalization is a process of finding relations, common attributes for a particular set of
entities; and finally defining a common superclass for them.

22. Why are cursors necessary in embedded SQL?


A cursor is an object used to store the output of a query for row-by-row processing by the application
programs. SQL statements operate on a set of data and return a set of data. On other hand, host language
programs operate on a row at a time. The cursors are used to navigate through a set of rows returned by
an embedded SQL SELECT statement. A cursor can be compared to a pointer.

24. What is the difference between a database schema and a database state?
The collection of information stored in a database at a particular moment in time is called database state
while the overall design of the database is called the database schema.

25. What is the purpose of SQL?


SQL stands for Structured Query Language whose main purpose is to interact with the relational databases
in the form of inserting, deleting and updating/modifying the data in the database.

28. What is the concept of sub-query in terms of SQL? What is Correlated Subquery in DBMS?
Sub-query or nested query is basically the query that is included inside some other query and can also be
called an inner query which is found inside the outer query. When a Subquery is executed for each of the
rows of the outer query then it is termed as a Correlated Subquery.
30. What is the main difference between UNION and UNION ALL?
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.

34. What integrity rules exist in the DBMS?


There are two major integrity rules that exist in the DBMS.
Entity Integrity: This states a very important rule that the value of a Primary key can never have a NULL
value.
Referential Integrity: This rule is related to the Foreign key which states that either the value of a Foreign
key is a NULL value or it should be the primary key of any other relation.

1. What is a CLAUSE in terms of SQL?


This is used with the SQL queries to fetch specific data as per the requirements on the basis of the
conditions that are put in the SQL. This is very helpful in picking the selective records from the complete
set of records.

43. How is the pattern matching done in the SQL?


With the help of the LIKE operator, pattern matching is possible in the SQL.’%’ is used with the LIKE
operator when it matches with the 0 or more characters, and ‘_’ is used to match the one particular
character.
Example:
SELECT * from Emp WHERE name like ‘b%’;
SELECT * from Emp WHERE name like ‘hans_’;

49. What do you mean by Entity type extension?


Compilation of similar entity types into one particular type which is grouped together as an entity set is
known as entity type extension.

50. What is conceptual design in dbms?


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.

52. What are temporary tables? When are they useful?


Temporary tables exist solely for a particular session, or whose data persists for the duration of the
transaction. The temporary tables are generally used to support specialized rollups or specific application
processing requirements. Unlike a permanent table, space is not allocated to a temporary table when it is
created. Space will be dynamically allocated for the table as rows are inserted. The CREATE GLOBAL
TEMPORARY TABLE command is used to create a temporary table in Oracle.

51. Differentiate between logical database design and physical database design. Show how this
separation leads to data independence.

Parameters Logical Database Design Physical Database Design

Maps or transforms the conceptual The specifications for the stored


schema (or an ER schema) from the database in terms of physical storage
high-level data model into a relational structures, record placement, and
Task database schema. indexes are designed.

The following criteria are often used to


The mapping can proceed in two stages: guide the choice of physical database
 System-independent mapping design options:
but data model-dependent  Response Time
Choice of  Tailoring the schemas to a  Space Utilization
criteria specific DBMS  Transaction Throughput

DDL statements in the language of the


chosen DBMS that specify the
conceptual and external level schemas
of the database system. But if the DDL
statements include some physical An initial determination of storage
design parameters, a complete DDL structures and the access paths for the
specification must wait until after the database files. This corresponds to
physical database design phase defining the internal schema in terms of
Result is completed. Data Storage Definition Language.

The database design is divided into several phases. The logical database design and physical database
design are two of them. This separation is generally based on the concept of the three-level architecture of
DBMS, which provides data independence. Therefore, we can say that this separation leads to data
independence because the output of the logical database design is the conceptual and external level
schemas of the database system which is independent of the output of the physical database design that is
an internal schema.

53. Explain different types of failures that occur in the Oracle database.
In the Oracle database following types of failures can occur:
Statement Failure
Bad data type
 Insufficient space
Insufficient Privileges (e.g., object privileges to a role)
User Process Failure
 The user performed an abnormal disconnect
 The user’s session was abnormally terminated
 The user’s program raised an address exception
User Error
 The user drops a table
 User damages data by modification
Instance Failure
Media Failure
 The user drops a table
 User damages data by modification
Alert Logs
 Records informational and error messages
 All Instance start-ups and shutdowns are recorded in the log

Q. What is embedded and dynamic SQL?


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.

S.No. Static (embedded) SQL Dynamic (interactive) SQL

In static SQL how database will be accessed is


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

2. It is more swift and efficient. It is less swift and efficient.

3. SQL statements are compiled at compile time. SQL statements are compiled at run time.

Parsing, validation, optimization, and Parsing, validation, optimization, and


generation of application plan are done at generation of application plan are done at
4. compile time. run time.

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

6. EXECUTE IMMEDIATE, EXECUTE and PREPARE EXECUTE IMMEDIATE, EXECUTE and


statements are not used. PREPARE statements are used.

7. It is less flexible. It is more flexible.

Q. What is the difference between CHAR and VARCHAR?


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

Q. Why we cannot use WHERE clause with aggregate functions like HAVING ?
The difference between the having and where clause in SQL is that the where clause canNOT be used with
aggregates, but the having clause can. Please note : It is not a predefined rule but by and large you’ll see
that in a good number of the SQL queries, we use WHERE prior to GROUP BY and HAVING after GROUP BY.
The Where clause acts as a pre filter where as Having as a post filter. The where clause works on row’s
data, not on aggregated data.

42. How can you get the alternate records from the table in the SQL?
If you want to fetch the odd numbers then the following query can be used:
SELECT EmpId from (SELECT rowno,EmpId from Emp) WHERE mod(rowno,2)=1;
If you want to fetch the even numbers, then the following query can be used:
SELECT EmpId from (SELECT rowno,EmpId from Emp) WHERE mod(rowno,2)=0;

8. How to print duplicate rows in a table?


Example :
| Id | NAME |
| 1 | Geeks |
| 2 | for |
| 3 | Geeks |
MySql :
select NAME from Person group by NAME having count(NAME) > 1;
Output :
| NAME |
| Geeks |

Q. 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

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. Query to find 2nd highest salary of an employee?
SELECT max(salary) FROM EMPLOYEES WHERE salary IN (SELECT salary FROM EMPLOYEEs MINUS SELECT
max(salary) FROM EMPLOYEES);
OR
SELECT max(salary) FROM EMPLOYEES WHERE salary <> (SELECT max(salary) FROM EMPLOYEES);
Q.Consider the following Employee table. How many rows are there in the result of following query?
ID salary DeptName
1 10000 EC
2 40000 EC
3 30000 CS
4 40000 ME
5 50000 ME
6 60000 ME
7 70000 CS
How many rows are there in the result of following query?
SELECT E.ID FROM Employee E WHERE EXISTS (SELECT E2.salary FROM Employee E2 WHERE
E2.DeptName = 'CS' AND E.salary > E2.salary)
Following 5 rows will be result of query as 3000 is the minimum salary of CS Employees and all these rows
are greater than 30000.
2
4
5
6
7
Q. 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)
Assuming Table name are Dept and Emp, trigger can be written as –
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;
Q. There is a table which contains two column Student and Marks, you need to find all the students,
whose marks are greater than average marks i.e. list of above average students.
SELECT student, marks FROM table WHERE marks > SELECT AVG(marks) from table;
Q.Name the student who has secured third highest marks using sub queries.
SELECT Emp1.Name FROM Employee Emp1 WHERE 2 = (SELECT COUNT(DISTINCT(Emp2.Salary)) FROM
Employee Emp2 WHERE Emp2.Salary > Emp1.Salary)
*LOGIC- Number of people with salary higher than this person will be 2.

You might also like