250+ TOP MCQs on Aggregate Functions and Nested Subqueries and Answers

Database Interview Questions and Answers on “Aggregate Functions and Nested Subqueries – 2”.

1.

SELECT dept_name, ID, avg (salary)
FROM instructor
GROUP BY dept_name;
This statement IS erroneous because

a) Avg(salary) should not be selected
b) Dept_id should not be used in group by clause
c) Misplaced group by clause
d) Group by clause is not valid in this query

Answer: b
Clarification: Any attribute that is not present in the group by clause must appear only inside an aggregate function if it appears in the select clause, otherwise the query is treated as erroneous.

2. SQL applies predicates in the _______ clause after groups have been formed, so aggregate functions may be used.
a) Group by
b) With
c) Where
d) Having

Answer: b
Clarification: The with clause provides away of defining a temporary relation whose definition is available only to the query in which the with clause occurs.

3. Aggregate functions can be used in the select list or the_______clause of a select statement or subquery. They cannot be used in a ______ clause.
a) Where, having
b) Having, where
c) Group by, having
d) Group by, where

Answer: b
Clarification: To include aggregate functions having clause must be included after where.

4. The ________ keyword is used to access attributes of preceding tables or subqueries in the from clause.
a) In
b) Lateral
c) Having
d) With

Answer: b
Clarification:

 Eg : SELECT name, salary, avg salary
            FROM instructor I1, lateral (SELECT avg(salary) AS avg salary
            FROM instructor I2
            WHERE I2.dept name= I1.dept name);

Without the lateral clause, the subquery cannot access the correlation variable
I1 from the outer query.

5. Which of the following creates a temporary relation for the query on which it is defined?
a) With
b) From
c) Where
d) Select

Answer: a
Clarification: The with clause provides a way of defining a temporary relation whose definition is available only to the query in which the with clause occurs.

6.

WITH max_budget (VALUE) AS
(SELECT MAX(budget)
FROM department)
SELECT budget
FROM department, max_budget
WHERE department.budget = MAX budget.value;

In the query given above which one of the following is a temporary relation?
a) Budget
b) Department
c) Value
d) Max_budget

Answer: d
Clarification: With clause creates a temporary relation.

7. Subqueries cannot:
a) Use group by or group functions
b) Retrieve data from a table different from the one in the outer query
c) Join tables
d) Appear in select, update, delete, insert statements.

Answer: c
Clarification: None.

8. Which of the following is not an aggregate function?
a) Avg
b) Sum
c) With
d) Min

Answer: c
Clarification: With is used to create temporary relation and its not an aggregate function.

9. The EXISTS keyword will be true if:
a) Any row in the subquery meets the condition only
b) All rows in the subquery fail the condition only
c) Both of these two conditions are met
d) Neither of these two conditions is met

Answer: a
Clarification: EXISTS keyword checks for existance of a condition.

10. How can you find rows that do not match some specified condition?
a) EXISTS
b) Double use of NOT EXISTS
c) NOT EXISTS
d) None of the mentioned

Answer: b

250+ TOP MCQs on Constraints and Answers Pdf

Database Multiple Choice Questions on “Constraints”.

1. _____________ express the number of entities to which another entity can be associated via a relationship set.
a) Mapping Cardinality
b) Relational Cardinality
c) Participation Constraints
d) None of the mentioned

Answer: a
Clarification: Mapping cardinality is also called as cardinality ratio.

2. An entity in A is associated with at most one entity in B, and an entity in B is associated with at most one entity in A.This is called as
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one

Answer: b
Clarification: Here one entity in one set is related to one one entity in other set.

3. An entity in A is associated with at most one entity in B. An entity in B, however, can be associated with any number (zero or more) of entities in A.
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one

Answer: d
Clarification: Here more than one entity in one set is related to one one entity in other set.

4. Data integrity constraints are used to:
a) Control who is allowed access to the data
b) Ensure that duplicate records are not entered into the table
c) Improve the quality of data entered for a specific property
d) Prevent users from changing the values stored in the table

Answer: c
Clarification: The data entered will be in a particular cell (i.e., table column).

5. Establishing limits on allowable property values, and specifying a set of acceptable, predefined options that can be assigned to a property are examples of:
a) Attributes
b) Data integrity constraints
c) Method constraints
d) Referential integrity constraints

Answer: b
Clarification: Only particular value satisfying the constraints are entered in the column.

6. Which of the following can be addressed by enforcing a referential integrity constraint?
a) All phone numbers must include the area code
b) Certain fields are required (such as the email address, or phone number) before the record is accepted
c) Information on the customer must be known before anything can be sold to that customer
d) Then entering an order quantity, the user must input a number and not some text (i.e., 12 rather than ‘a dozen’)

Answer: c
Clarification: None.

7. ______ is a special type of integrity constraint that relates two relations & maintains consistency across the relations.
a) Entity Integrity Constraints
b) Referential Integrity Constraints
c) Domain Integrity Constraints
d) Domain Constraints

Answer: b
Clarification: None.

8. Which one of the following uniquely identifies the elements in the relation?
a) Secondary Key
b) Primary key
c) Foreign key
d) Composite key

Answer: b
Clarification: Primary key checks for not null and uniqueness constraint.

9. Drop Table cannot be used to drop a table referenced by a _________ constraint.
a) Local Key
b) Primary Key
c) Composite Key
d) Foreign Key

Answer: d
Clarification: Foreign key is used when primary key of one relation is used in another relation.

10. ____________ is preferred method for enforcing data integrity
a) Constraints
b) Stored Procedure
c) Triggers
d) Cursors

Answer: a
Clarification: Constraints are specified to restrict entries in the relation.

250+ TOP MCQs on Application Architectures and Answers

Database Multiple Choice Questions on “Application Architectures”.

1. Which of the following is true for Seeheim model?
a) Presentation is abstracted from dialogue and Application
b) Presentation and Dialogue is abstracted from Application
c) Presentation and Application is abstracted from Dialogue
d) None of the mentioned

Answer: a
Clarification: Presentation is abstracted from dialogue and application.

2. Which of the unit operation is used in Model view controller?
a) Is a Decomposition
b) Part Whole Decomposition
c) All of the mentioned
d) None of the mentioned

Answer: b
Clarification: Part whole decomposition is applied to MVC.

3. Memory address refers to the successive memory words and the machine is called as _______________
a) word addressable
b) byte addressable
c) bit addressable
d) Terra byte addressable

Answer: a
Clarification: Part whole decomposition is applied to MVC.

4. Which layer deals which deals with user interaction is called _____________ layer.
a) Business logic
b) Presentation
c) User interaction
d) Data access

Answer: b
Clarification: The single application may have several different versions of this layer, corresponding to distinct kinds of interfaces such as Web browsers, and user interfaces of mobile phones, which have much smaller screens.

5. The _____________ layer, which provides a high-level view of data and actions on data.
a) Business logic
b) Presentation
c) User interaction
d) Data access

Answer: a
Clarification: The single application may have several different versions of this layer, corresponding to distinct kinds of interfaces such as Web browsers, and user interfaces of mobile phones, which have much smaller screens.

6. The ______________ layer, which provides the interface between the business-logic layer and the underlying database.
a) Business logic
b) Presentation
c) User interaction
d) Data access

Answer: d
Clarification: Many applications use an object-oriented language to code the business-logic layer, and use an object-oriented model of data, while the underlying database is a relational database.

7. The _____________ system is widely used for mapping from Java objects to relations.
a) Hibernate
b) Object oriented
c) Objective
d) None of the mentioned

Answer: a
Clarification: In Hibernate, the mapping from each Java class to one or more relations is specified in a mapping file.

8. Which among the following are the functions that any system with a user interface must provide?
a) Presentation
b) Dialogue
c) All of the mentioned
d) None of the mentioned

Answer: a
Clarification: Presentation and Application are the functions that any system with a user interface must provide.

9. Which of the following is the main task accomplished by the user?
a) Compose a document
b) Create a spread sheet
c) Send mail
d) All of the mentioned

Answer: d
Clarification: All of the mentioned are the main task accomplished by the user.

10. What are the portability concerns founded in Seeheim model?
a) Replacing the presentation toolkit
b) Replacing the application toolkit
c) Replacing the dialogue toolkit
d) Replacing the presentation & application toolkit

Answer: d
Clarification: The portability concerns founded in Seeheim model are- Replacing the presentation toolkit and Replacing the application toolkit.

Database Questions & Answers – Bitmap Indices and Answers

Database Multiple Choice Questions on “Bitmap Indices”.

1. Bitmap indices are a specialized type of index designed for easy querying on ___________
a) Bit values
b) Binary digits
c) Multiple keys
d) Single keys

Answer: c
Clarification: Each bitmap index is built on a single key.

2. A _______ on the attribute A of relation r consists of one bitmap for each value that A can take.
a) Bitmap index
b) Bitmap
c) Index
d) Array

Answer: a
Clarification: A bitmap is simply an array of bits.

3.

SELECT *
FROM r
WHERE gender = ’f’ AND income level = ’L2’;

In this selection, we fetch the bitmaps for gender value f and the bitmap for income level value L2, and perform an ________ of the two bitmaps.
a) Union
b) Addition
c) Combination
d) Intersection

Answer: d
Clarification: We compute a new bitmap where bit i has value 1 if the ith bit of the two bitmaps are both 1, and has a value 0 otherwise.

4. To identify the deleted records we use the ______________
a) Existence bitmap
b) Current bitmap
c) Final bitmap
d) Deleted bitmap

Answer: a
Clarification: The bitmaps which are deleted are denoted by 0.

5. Bitmaps can be used as a compressed storage mechanism at the leaf nodes of ________ for those values that occur very frequently.
a) B-trees
b) B+-trees
c) Bit trees
d) Both B-trees and B+-trees

Answer: b
Clarification: Bitmaps are combined and stored in a B+ tree.

6. Bitmaps can be combined with regular B+-tree indices for relations where a few attribute values are extremely common, and other values also occur, but much less frequently.
a) Bitmap, B-tree
b) Bitmap, B+tree
c) B-tree, Bitmap
d) B+tree, Bitmap

Answer: b
Clarification: Bitmaps are combined and stored in a B+ tree.

7. In a B+-tree index ______ for each value, we would normally maintain a list of all records with that value for the indexed attribute.
a) Leaf
b) Node
c) Root
d) Link

Answer: a
Clarification: Bitmaps are combined and stored in a B+ tree.

8. A tablespace is further broken down into ________
a) Tablespace
b) Segments
c) Extents
d) Blocks

Answer: b
Clarification: Segment names are used in create table and create index commands to place tables or indexes on specific database devices.

9. In ordered indices the file containing the records is sequentially ordered, a ___________ is an index whose search key also defines the sequential order of the file.
a) Clustered index
b) Structured index
c) Unstructured index
d) Nonclustered index

Answer: a
Clarification: Clustering index are also called primary indices; the term primary index may appear to denote an index on a primary key, but such indices can in fact be built on any search key.

10. Indices whose search key specifies an order different from the sequential order of the file are called ___________ indices.
a) Nonclustered
b) Secondary
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: Nonclustering index are also called secondary indices.

250+ TOP MCQs on Querying Database and Answers

Database Questions and Answers for Experienced people on ” Querying database″.

1. Which s essential a business problem not a data problem:
a) Data
b) Database
c) Database design
d) All of the mentioned

Answer: c
Clarification: SQL-99 is the most recent version of standard SQL prescribed by the ANSI.

2. Which is primarily the result of a thorough understanding of information about an enterprise:
a) Data
b) Database
c) Database design
d) Data modeling

Answer: d
Clarification: Data modelling designs the data in a secured manner.

3. McFadden has defined normalization in his which book___________
a) Database modern management
b) Management database of modern
c) Modern database management
d) Database management

Answer: c
Clarification: SQL-99 is the most recent version of standard SQL prescribed by the ANSI.

4. The database design prevents some data from being represented due to _______
a) Deletion anomalies
b) Insertion anomalies
c) Update anomaly
d) None of the mentioned

Answer: b
Clarification: Insertion anomaly is due to confusion in data deletion or insertion.

5. How many types of insertion anomalies:
a) 1
b) 2
c) 3
d) 4

Answer: b
Clarification: Insertion anomaly is due to confusion in data deletion or insertion.

6. Who developed the normalization process:
a) E.F. codd
b) F.F. codd
c) E.E. codd
d) None of the mentioned

Answer: a
Clarification: Normalization helps in improving the quality of the data.

7. E.F.Codd developed the normalization process in the which early:
a) 1969
b) 1970
c) 1971
d) 1972

Answer: b
Clarification: Normalization helps in improving the quality of the data.

8. Which is a bottom-up approach to database design that design by examining the relationship between attributes:
a) Functional dependency
b) Database modeling
c) Normalization
d) Decomposition

Answer: c
Clarification: Normalization helps in improving the quality of the data.

9. Which is the process of breaking a relation into multiple relations:
a) Functional dependency
b) Database modeling
c) Normalization
d) Decomposition

Answer: d
Clarification: SQL-99 is the most recent version of standard SQL prescribed by the ANSI.

10. Which formal method that locates and analyses relation schemas on the basis of their primary, candidate keys, and the FD’s that are present among the attributes of these schemas:
a) Functional dependency
b) Database modeling
c) Normalization
d) Decomposition

Answer: c
Clarification: Normalization helps in improving the quality of the data.

250+ TOP MCQs on Lock Release and Undo Operations and Answers

Database Multiple Choice Questions on “Lock Release and Undo Operations”.

1. Which lock should be obtained to prevent a concurrent transaction from executing a conflicting read, insert or delete operation on the same key value.
a) Higher-level lock
b) Lower-level lock
c) Read only lock
d) Read write

Answer: a
Clarification: Operations acquire lower-level locks while they execute, but release them when they complete; the corresponding transaction must however retain a higher-level lock in a two-phase manner to prevent concurrent transactions from executing conflicting actions.

2. Once the lower-level lock is released, the operation cannot be undone by using the old values of updated data items, and must instead be undone by executing a compensating operation; such an operation is called
a) Logical operation
b) Redo operation
c) Logical undo operation
d) Undo operation

Answer: a
Clarification: It is important that the lower-level locks acquired during an operation are sufficient to perform a subsequent logical undo of the operation.

3. Which of the following is used for undo operations alone?
a) Logical logging
b) Physical logging
c) Physical log records
d) Physical logging and Physical log records

Answer: a
Clarification: If the operation inserted an entry in a B+-tree, the undo information U would indicate that a deletion operation is to be performed, and would identify the B+-tree and what entry to delete from the tree. Such logging of information about operations is called logical logging.

4. Redo operations are performed exclusively using
a) Logical logging
b) Physical logging
c) Physical log records
d) Both Physical logging and Physical log records

Answer: d
Clarification: Logging of old-value and new-value information is called physical logging.

5. To perform logical redo or undo, the database state on disk must be operation ___________ that is, it should not have partial effects of any operation.
a) Persistent
b) Resistant
c) Consistent
d) None of the mentioned

Answer: c
Clarification: Data structures such as B+-trees would not be in a consistent state, and neither logical redo nor logical undo operations can be performed on an inconsistent data structure.

6. An operation is said to be __________ if executing it several times in a row gives the same result as executing it once.
a) Idempotent
b) Changed
c) Repetitive
d) All of the above

Answer: a
Clarification: Operations such as inserting an entry into a B+-tree may not be idempotent, and the recovery algorithm must therefore make sure that an operation that has already been performed is not performed again.

7. Immediate database modification technique uses
a) Both undo and redo
b) Undo but no redo
c) Redo but no undo
d) Neither undo nor redo

Answer: a
Clarification: Undo erases all the changes and redo makes the deleted changes.

8. Shadow paging has
a) no redo
b) no undo
c) redo but no undo
d) neither redo nor undo

Answer: a
Clarification: Undo erases all the changes and redo makes the deleted changes.

9. For correct behaviour during recovery, undo and redo operation must be
a) Commutative
b) Associative
c) Idempotent
d) Distributive

Answer: c
Clarification: Undo erases all the changes and redo makes the deleted changes.

10. If ___________ are not obtained in undo operation it will cause problem in undo-phase.
a) Higher-level lock
b) Lower-level lock
c) Read only lock
d) Read write

Answer: b
Clarification: Operations acquire lower-level locks while they execute, but release them when they complete; the corresponding transaction must however retain a higher-level lock in a two-phase manner to prevent concurrent transactions from executing conflicting actions.