DBMS Interview Questions
DBMS Interview Questions
What is Data?
Explain Normalization
Differentiate between 3nf and BCNF.
Levels of Data abstraction?
What is DML ?
How to join two tables?
Explain Triggers?
Expalin Group by Clause
[Link] is a View.
[Link] is index.
[Link] is Normalisation?
[Link]. between 3nf and Bcnf form?
[Link] diff types of Joins?
[Link] types of Keys?
7. What is candidate key?
8. What is trigger?
9. What are different types of two phase lockings(2pl)?
10. What is a deadlock?
11. What are triggers?
12. What are different categories of data models?
13. What is schema?
14. What are types of schema?
15. What is Data independency?
16. What are different DBMS languages?
17. What are different types of DBMS?
18. What is an entity?
19. What are attributes?
What is schema ?
A schema is collection of database objects of a user.
What are 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.
[Link] redundancy and inconsistency
2. Difficulty in accessing data
3. Data isolation – multiple files and formats
4. Integrity problems
5. Atomicity of updates
[Link] access by multiple users
7. Security problems
Source: [Link]
What are super, primary, candidate and foreign keys?
Ans: A superkey 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 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 that one primary keys in a table.
Foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another
table. See this for an example.
What is the difference between primary key and unique constraints?
Ans: 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.
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.
Source: [Link]
What is the difference between having and where clause?
Ans: HAVING is used to specify a condition for a group or an aggregate function used in select
statement. The WHERE clause selects before grouping. The HAVING clause selects rows after
grouping. Unlike HAVING clause, the WHERE clause cannot contain aggregate functions.
(See this for examples)
What is a view in SQL? How to create one
Ans: A view is a virtual table based on the result-set of an SQL statement. We can create using
create view syntax.
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
What are the uses of view?
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; for example a view could appear as Sales2000 or
Sales2001, transparently partitioning the actual underlying table
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 presentsv.
6. Depending on the SQL engine used, views can provide extra security
Source: Wiki Page
What is a Trigger?
Ans: A Trigger is a code that 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 database.
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.
What is the difference between Trigger and Stored Procedure?
Ans: Unlike Stored Procedures, Triggers cannot be called directly. They can only be associated with
queries.
What is a transaction? What are ACID properties?
Ans: A Database Transaction is a set of database operations that must be treated as whole, means
either all operations are executed or none of them.
An example can be 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.
What are indexes?
Ans: 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 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 disk, but they allow faster search according to different
frequently searched values.
What are clustered and non-clustered Indexes?
Ans: Clustered indexes is the index according to which data is physically stored on disk. Therefore,
only one clustered index can be created on a given database table.
Non-clustered indexes don’t define 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.
We will soon be covering more DBMS questions. Please write comments if you find anything
incorrect, or you want to share more information about the topic discussed above.
. What is database?
A database is a logically coherent collection of data with some inherent meaning, representing some aspect
of real world and which is designed, built and populated with data for a specific purpose.
2. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other words it is
general-purpose software that provides the users with the processes of defining, constructing and
manipulating the database for various applications.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. What are the advantages of DBMS?
1. Redundancy is controlled.
2. Unauthorised access is restricted.
3. Providing multiple user interfaces.
4. Enforcing integrity constraints.
5. Providing backup and recovery.
5. What are the disadvantage in File Processing System?
1. Data redundancy and inconsistency.
2. Difficult in accessing data.
3. Data isolation.
4. Data integrity.
5. Concurrent access is not possible.
6. Security Problems.
6. Describe the three levels of data abstraction?
The are three levels of abstraction:
1. Physical level: The lowest level of abstraction describes how data are stored.
2. Logical level: The next higher level of abstraction, describes what data are stored in database and what
relationship among those data.
3. View level: The highest level of abstraction describes only part of entire database.
7. Define the “integrity rules”?
There are two Integrity rules.
1. Entity Integrity: States that “Primary key cannot have NULL value”
2. Referential Integrity: States that “Foreign Key can be either a NULL value or should be Primary Key
value of other relation.
8. What is extension and intension?
1. Extension: It is the number of tuples present in a table at any instance. This is time dependent.
2. Intension: It is a constant value that gives the name, structure of table and the constraints laid on it.
9. What is System R? What are its two major subsystems?
System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It is a
prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be
used in a real life environment to solve real life problems, with performance at least comparable to that of
existing system.
Its two subsystems are
1. Research Storage
2. System Relational Data System.
10. How is the data structure of System R different from the relational structure?
Unlike Relational systems in System R
1. Domains are not supported
2. Enforcement of candidate key uniqueness is optional
3. Enforcement of entity integrity is optional
4. Referential integrity is not enforced
11. What is Data Independence?
Data independence means that “the application is independent of the storage structure and access strategy
of data”. In other words, The ability to modify the schema definition in one level should not affect the
schema definition in the next higher level.
Two types of Data Independence:
1. Physical Data Independence: Modification in physical level should not affect the logical level.
2. Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve 12. What is a view? How it is related to
data independence?
A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is
instead derived from one or more underlying base table. In other words, there is no stored file that direct
represents the view instead a definition of view is stored in data dictionary.
Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the
effects of restructuring and growth in the database. Hence accounts for logical data independence.
13. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and constraints.
14. What is E-R model?
This data model is based on real world that consists of basic objects called entities and of relationship
among these objects. Entities are described in a database by a set of attributes.
15. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance variables with in
the object. An object also contains bodies of code that operate on the object. These bodies of code are
called methods. Objects that contain same types of values and the same methods are grouped together into
classes.
16. What is an Entity?
It is a ‘thing’ in the real world with an independent existence.
17. What is an Entity type?
It is a collection (set) of entities that have same attributes.
18. What is an Entity set?
It is a collection of all entities of particular entity type in the database.
19. What is an Extension of entity type?
The collections of entities of a particular entity type are grouped together into an entity set.
20. What is Weak Entity set?
An entity set may not have sufficient attributes to form a primary key, and its primary key compromises of
its partial key and primary key of its parent entity, then it is said to be Weak Entity set.
21. What is an attribute?
It is a particular property, which describes the entity.
22. What is a Relation Schema and a Relation?
A relation Schema denoted by R(A1, A2, …, An) is made up of the relation name R and the list of
attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set
tuples (t1, t2, t3, …, tn). Each tuple is an ordered list of n-values t=(v1,v2, …, vn).
23. What is degree of a Relation?
It is the number of attribute of its relation schema.
24. What is Relationship?
It is an association among two or more entities.
25. What is Relationship set?
The collection (or set) of similar relationships.
26. What is Relationship type?
Relationship type defines a set of associations or a relationship set among a given set of entity types.
27. What is degree of Relationship type?
It is the number of entity type participating.
28. What is DDL (Data Definition Language)?
A data base schema is specifies by a set of definitions expressed by a special language called DDL.
29. What is VDL (View Definition Language)?
It specifies user views and their mappings to the conceptual schema.
30. What is SDL (Storage Definition Language)?
This language is to specify the internal schema. This language may specify the mapping between two
schemas.
31. What is Data Storage – Definition Language?
The storage structures and access methods used by database system are specified by a set of definition in a
special type of DDL called data storage-definition language.
32. What is DML (Data Manipulation Language)?
This language that enable user to access or manipulate data as organised by appropriate data model.
1. Procedural DML or Low level: DML requires a user to specify what data are needed and how to get those
data.
2. Non-Procedural DML or High level: DML requires a user to specify what data are needed without
specifying how to get those data.
33. What is DML Compiler?
It translates DML statements in a query language into low-level instruction that the query evaluation engine
can understand.
34. What is Query evaluation engine?
It executes low-level instruction generated by compiler.
35. What is DDL Interpreter?
It interprets DDL statements and record them in tables containing metadata.
36. What is Record-at-a-time?
The Low level or Procedural DML can specify and retrieve each record from a set of records. This retrieve
of a record is said to be Record-at-a-time.
37. What is Set-at-a-time or Set-oriented?
The High level or Non-procedural DML can specify and retrieve many records in a single DML statement.
This retrieve of a record is said to be Set-at-a-time or Set-oriented.
38. What is Relational Algebra?
It is procedural query language. It consists of a set of operations that take one or two relations as input and
produce a new relation.
1. What is DBMS ?
Database management system is a collection of programs that enables user to store , retrieve , update and
delete information from a database .
3. What is SQL ?Structured Query Language(SQL) is a language designed specifically for communicating
with databases. SQL is an ANSI (American National Standards Institute) standard .
DDL is used to define the structure that holds the data. For example. table
SQL JOIN allows us to “lookup” records on other table based on the given conditions between two tables.
For example, if we have the department ID of each employee, then we can use this department ID of the
employee table to join with the department ID of department table to lookup department names.
UNION operation allows us to add 2 similar data sets to create resulting data set that contains all the data
from the source data sets. Union does not require any condition for joining. For example, if you have 2
employee tables with same structure, you can UNION them to create one result set that will contain all the
employees from both of the tables.
WHERE and HAVING both filters out records based on one or more conditions. The difference is,
WHERE clause can only be applied on a static non-aggregated column whereas we will need to use
HAVING for aggregated columns.
This question, often asked in many interviews, does not make any sense to me. The problem here is how do
you define which record is first and which is second. Which record is retrieved first from the database is not
deterministic. It depends on many uncontrollable factors such as how database works at that moment of
execution etc. So the question should really be – “how to select any 5 records from the table?” But
whatever it is, here is the solution:
In Oracle,
SELECT *
FROM EMP
WHERE ROWNUM <= 5;
6. Define Primary Key?
The primary key is the columns used to uniquely identify each row of a
table.
A table can have only one primary key.
No primary key value can appear in more than one row in the table.
7. Define Unique Key?
Unique key is a one or more column that must be unique for each row of the
table.
It is similar to primary key. Primary key column will not accept a null.
Whereas the unique key column will accept a null values.
8. Compare and contrast TRUNCATE and DELETE for a table?
Both the truncate and delete command have the desired outcome of getting
rid of all the rows in a table. The difference between the two is that the
truncate command is a DDL operation and just moves the high water mark
and produces a now rollback. The delete command, on the other hand, is a
DML operation, which will produce a rollback and thus take longer to
complete.
9. What is cursors?
Cursor is a database object used by applications to manipulate data in a set
on a row-by-row basis, instead of the typical SQL commands that operate on
all the rows in the set at one time.
Transactional
Snapshot
Merge
DISCUSS
14. What is User Defined Functions?
User-Defined Functions allow to define its own T-SQL functions that can
accept 0 or more parameters and return a single scalar data value or a table
data type.
DISCUSS
15. Define Self Join?
Self join means joining one table with itself.
The self join can be viewed as a join of two copies of the same table.
16. Define Joins?
A Join combines columns and data from two or more tables (and in rare
cases, of one table with itself).
DISCUSS
17. What are the types of Joins?
Equi joins
Cartesian Joins
Outer Joins
Self Joins.
18. Define Equi Joins?
A Equi Join is a join in which the join comparison operator is an equality.
When two tables are joined together using equality or values in one or more
columns, they make an Equi Join.
20. What are tree SQL keywords used to change or set someone's permissions?
GRANT, DENY, and REVOKE
Q.1 Which of the following relational algebra operations do not require the participating tables to be
union-compatible?
(A) Union (B) Intersection
(C) Difference (D) Join
Ans: (D)
Ans: (B)
Ans: (C )
Ans: (A)
Ans: (C )
Q.6 The language that requires a user to specify the data to be retrieved without specifying
exactly how to get it is
(A) Procedural DML. (B) Non-Procedural DML.
(C) Procedural DDL. (D) Non-Procedural DDL.
Ans: (B)
Ans: (A)
Q.8 The rule that a value of a foreign key must appear as a value of some specific table is called a
(A) Referential constraint. (B) Index.
(C) Integrity constraint. (D) Functional dependency.
Ans: (A) The rule that a value of a foreign key must appear as a value of some specific table
is called a referential constraint. (Referential integrity constraint is concerned with foreign key)
Q.9 The clause in SQL that specifies that the query result should be sorted in ascending or descending
order based on the values of one or more columns is
(A) View (B) Order by
(C) Group by (D) Having
Ans: (B) The clause in SQL that specifies that the query result should be sorted in ascending or
descending order based on the values of one or more columns is ORDER BY. (ORDER BY clause
is used to arrange the result of the SELECT statement)
Ans: (A) Disjoint less constraint requires that an entity belongs to no more than one level entity set.
(Disjoint less constraint means that an entity can be a member of at most one of the subclasses of
the specialization.)
Q.11 According to the levels of abstraction, the schema at the intermediate level is called
(A) Logical schema. (B) Physical schema.
(C) Subschema. (D) Super schema.
Ans: According to the levels of abstraction, the schema at the intermediate level is
called conceptual schema.
(Note: All the options given in the question are wrong.)
Q.12 It is an abstraction through which relationships are treated as higher level entities
(A) Generalization. (B) Specialization.
(C) Aggregation. (D) Inheritance.
Ans: (C ) It is an abstraction through which relationships are treated as higher level entities
Aggregation. (In ER diagram, aggregation is used to represent a relationship as an entity set.)
Q.13 A relation is in ____________ if an attribute of a composite key is dependent on an attribute of
other composite key.
(A) 2NF (B) 3NF
(C) BCNF (D) 1NF
Ans: (B) (Data integrity means that the data must be valid according to the given constraints.
Therefore, the data is accurate and consistent.)
Ans: (B) What are the desirable properties of a decomposition – dependency preserving.
(Lossless join and dependency preserving are the two goals of the decomposition.)
Ans: (A)
Q.17 The operation which is not considered a basic operation of relational algebra is
(A) Join. (B) Selection.
(C) Union. (D) Cross product.
Ans: (A)
Ans: (C)
Ans: (D)
Ans: (A)
Ans: (B)
Ans: (B)
Q.23 As per equivalence rules for query transformation, selection operation distributes over
(A Union. (B) Intersection (C) Set difference. (D) All of the above.
Ans: (D)
Q.24 The metadata is created by the
(A) DML compiler (B) DML pre-processor
(C) DDL interpreter (D) Query interpreter
Ans: (C)
Q.25 When an E-R diagram is mapped to tables, the representation is redundant for
(A) weak entity sets (B) weak relationship sets
(C) strong entity sets (D) strong relationship sets
Ans: (B)
Ans: (A)
Ans: (A)
.28 The default level of consistency in SQL is
(A) repeatable read (B) read committed
(C) read uncommitted (D) serializable
Ans: (D)
Ans: (C)
Ans: (A)
Q.31 If the closure of an attribute set is the entire relation then the attribute set is a
(A) superkey (B) candidate key
(C) primary key (D) not a key
Ans: (A)
Ans: (C)
Q.33 If two relations R and S are joined, then the non matching tuples of both R and S are ignored in
(A) left outer join (B) right outer join
(C) full outer join (D) inner join
Ans: (D)
Q.34 The keyword to eliminate duplicate rows from the query result in SQL is
(A) DISTINCT (B) NO DUPLICATE
(C) UNIQUE (D) None of the above
` Ans: (C)
Q.35 In 2NF
(A) No functional dependencies (FDs) exist.
(B) No multivalued dependencies (MVDs) exist.
(C) No partial FDs exist.
(D) No partial MVDs exist.
Ans: (C)
Q.37 In an E-R, Y is the dominant entity and X is a subordinate entity. Then which of the
following is incorrect :
(A) Operationally, if Y is deleted, so is X
(B) existence is dependent on Y.
(C) Operationally, if X is deleted, so is Y.
(D) Operationally, if X is deleted, & remains the same.
Ans: (C)
Ans: (C)
Q.39 Which of the following aggregate functions does not ignore nulls in its results?.
(A) COUNT . (B) COUNT (*)
(C) MAX (D) MIN
Ans: (B)
Q.40 R (A,B,C,D) is a relation. Which of the following does not have a lossless join dependency
preserving BCNF decomposition
(A) AgB, BgCD (B) AgB, BgC, CgD .
(C) ABgC, CgAD (D) AgBCD
Ans: (D)
Q.41 Consider the join of relation R with a relation S. If R has m tuples and S has n tuples, then
the maximum and minimum size of the join respectively are
(A) m+n and 0 (B) m+n and |m-n|
(C) mn and 0 (D) mn and m+n
Ans: (C)
Ans: (D)
Q.44 Which of the following statement on the view concept in SQL is invalid?
(A) All views are not updateable
(B) The views may be referenced in an SQL statement whenever tables are referenced.
(C) The views are instantiated at the time they are referenced and not when they are
defined.
(D) The definition of a view should not have GROUP BY clause in it.
Ans: (D)
Q.45 Which of the following concurrency control schemes is not based on the serializability
property?
(A) Two – phase locking (B) Graph-based locking
(C) Time-stamp based locking (D) None of these .
Ans: (D)
Ans: (D)
Q.47 If an entity can belong to only one lower level entity then the constraint is
(A) disjoint (B) partial
(C) overlapping (D) single
Ans: (B)
Ans: (C )
Ans: (D)
Q.50 Use of UNIQUE while defining an attribute of a table in SQL means that the attribute values are
(A) distinct values (B) cannot have NULL
(C) both (A) & (B) (D) same as primary key
Ans: (C)
Q.51 The cost of reading and writing temporary files while evaluating a query can be reduced by
(A) building indices (B) pipelining
(C) join ordering (D) none of the above
Ans: (B)
Q.52 A transaction is in __________ state after the final statement has been executed.
(A) partially committed (B) active
(C) committed (D) none of the above
Ans: (C)
Ans: (B)
Q.54 The statement that is executed automatically by the system as a side effect of the modification of
the database is
(A) backup (B) assertion
(C) recovery (D) trigger
Ans: (D)
Q.55 The normal form that is not necessarily dependency preserving is
(A) 2NF (B) 3NF
(C) BCNF (D) 4NF
Ans: (A)
Ans: (A)
Ans: (B)
Q.58 The division operator divides a dividend A of degree m+n by a divisor relation B of degree n and
produces a result of degree
(A) m – 1 (B) m + 1
(C) m * m (D) m
Ans: (D)
Q.60 Assume transaction A holds a shared lock R. If transaction B also requests for a shared lock on R.
(A) It will result in a deadlock situation.
(B) It will immediately be rejected.
(C) It will immediately be granted.
(D) It will be granted as soon as it is released by A .
Ans: (C)
Q.61 In E-R Diagram total participation is represented by
(A) double lines (B) Dashed lines
(C) single line (D) Triangle
Ans: (A)
Ans: (C)
Q.64 Union operator is a :
(A) Unary Operator (B) Ternary Operator
(C) Binary Operator (D) Not an operator
Ans: (C)
Ans: (A)
Q.66 Manager salary details are hidden from the employee .This is
(A) Conceptual level data hiding.
(B) External level data hiding.
(C) Physical level data hiding.
(D) None of these.
Ans: (A)
Ans: (A)
Q.68 Which two files are used during operation of the DBMS?
(A) Query languages and utilities
(B) DML and query language
(C) Data dictionary and transaction log
(D) Data dictionary and query language
Ans: (C )
Q.69 A list consists of last names, first names, addresses and pin codes. If all people in the list have
the same last name and same pin code a useful key would be
(A) the pin code
(B) the last name
(C) the compound key first name and last name
(D) Tr from next page
Ans: (C )
Q.70 In b-tree the number of keys in each node is ____ than the number of its children.
(A) one less (B) same
(C) one more (D) half
Ans: (A)
Ans: (D)
Q.72 Which normal form is considered adequate for normal relational database design?
(A) 2NF (B) 5NF
(C) 4NF (D) 3NF
Ans: (D)
Q.73 Which of the following addressing modes permits relocation without any change over in the
code?
(A) Indirect addressing (B) Indexed addressing
(C) PC relative addressing (D) Base register addressing
Ans: (B)
Q.74 In a multi-user database, if two users wish to update the same record at the same time, they
are prevented from doing so by
(A) jamming (B) password
(C) documentation (D) record lock
Ans: (D)
Q.76 Which of the following relational algebraic operations is not from set theory?
(A) Union (B) Intersection
(C) Cartesian Product (D) Select
Ans: (D)
Ans: (A)
Q.78 If both the functional dependencies : X®Y and Y®X hold for two attributes X and Y then the
relationship between X and Y is
(A) M:N (B) M:1
(C) 1:1 (D) 1:M
Ans: (C)
Q.79 What will be the number of columns and rows respectively obtained for the operation, A- B, if A
B are Base union compatible and all the rows of a are common to B? Assume A has 4 columns and
10 rows; and B has 4 columns and 15 rows
(A) 4,0 (B) 0,0
(C) 4,5 (D) 8,5
Ans: (A)
Q.80 For correct behaviour during recovery, undo and redo operation must be
(A) Commutative (B) Associative
(C) idempotent (D) distributive
Ans: (C)
Ans: (D)
Ans: (A)
Q.83 The part of a database management system which ensures that the data remains in a consistent state
is
(A) authorization and integrity manager
(B) buffer manager
(C) transaction manager
(D) file manager
Ans: (C)
Ans: (A)
Ans: (D)
Ans: (A)
Ans: (D)
Ans: (D)
Ans: (D)
Ans: (D)
Q.92 Whenever two independent one-to-many relationships are mixed in the same relation, a _______
arises.
(A) Functional dependency (B) Multi-valued dependency
(C) Transitive dependency (D) Partial dependency
Ans:(B)
Ans: (D)
Ans: (A)
Q.96 Which of the following constitutes a basic set of operations for manipulating relational data?
(A) Predicate calculus (B) Relational calculus
(C) Relational algebra (D) SQL
Ans: (C)
Ans: (A)
Ans: (C)
Ans: (C)
Q.100 _______ operator is used to compare a value to a list of literals values that have been specified.
(A) Like (B) COMPARE
(C) BETWEEN (D) IN
Ans: (A)