DBMS MCQ Bank
DBMS MCQ Bank
DBMS MCQ Bank
5. Which term refers to the process of combining data from two or more tables into a single result set?
a) Aggregation
b) Normalization
c) Joins
d) Indexing
Answer: c) Joins
6. What does the acronym "SQL" stand for in the context of databases?
a) Structured Query Language
b) Sequential Query Language
c) Simplified Query Logic
d) Standardized Query Log
Answer: b) To ensure data integrity by grouping multiple operations into a single unit
9. Which database term refers to a collection of related data entries treated as a single unit?
a) Record
b) Attribute
c) Entity
d) Index
Answer: c) Entity
Answer: c) To speed up data retrieval by creating a data structure for quick access
11. Which type of DBMS stores data in tables with rows and columns, and uses SQL as the query
language?
a) Object-Relational Database Management System (ORDBMS)
b) NoSQL Database Management System
c) Relational Database Management System (RDBMS)
d) Hierarchical Database Management System
12. In an Object-Relational Database Management System (ORDBMS), what additional feature does it
provide compared to a traditional RDBMS?
a) Support for complex data types and objects
b) Exclusive use of SQL for data querying
c) Faster data retrieval using NoSQL techniques
d) Limited data storage capacity
13. Which type of DBMS is designed to handle unstructured and semi-structured data, and provides
flexible schemas?
a) Relational Database Management System (RDBMS)
b) NoSQL Database Management System
c) Hierarchical Database Management System
d) Object-Oriented Database Management System (OODBMS)
14. What is the main advantage of using a NoSQL database over a traditional RDBMS?
a) NoSQL databases support complex joins and transactions.
b) NoSQL databases provide a flexible schema for dynamic data.
c) NoSQL databases use only SQL for data querying, which simplifies the process.
d) NoSQL databases have better support for complex data types and objects.
15. Which type of DBMS is best suited for handling relationships and ensuring data integrity using
constraints like primary keys and foreign keys?
a) Object-Relational Database Management System (ORDBMS)
b) NoSQL Database Management System
c) Relational Database Management System (RDBMS)
d) Hierarchical Database Management System
16. Which type of DBMS uses a hierarchical structure with parent-child relationships between data
elements?
a) Relational Database Management System (RDBMS)
b) NoSQL Database Management System
c) Object-Oriented Database Management System (OODBMS)
d) Hierarchical Database Management System
17. Which type of DBMS is best suited for handling complex and interconnected data objects, often
used in engineering and scientific applications?
a) Hierarchical Database Management System
b) Relational Database Management System (RDBMS)
c) Object-Oriented Database Management System (OODBMS)
d) Object-Relational Database Management System (ORDBMS)
18. What is the primary purpose of using an Object-Relational Database Management System
(ORDBMS)?
a) To enforce data integrity constraints using primary keys and foreign keys
b) To provide a flexible schema for handling unstructured data
c) To handle complex data objects with attributes and methods
d) To optimize data retrieval and storage using indexes
19. Which type of DBMS is best suited for handling large amounts of data with high read and write
throughput, often used in big data and real-time applications?
a) Object-Relational Database Management System (ORDBMS)
b) NoSQL Database Management System
c) Relational Database Management System (RDBMS)
d) Hierarchical Database Management System
Answer: b)
20. In which type of DBMS is data stored in objects with attributes and methods, providing support for
inheritance and polymorphism?
a) Relational Database Management System (RDBMS)
b) NoSQL Database Management System
c) Object-Oriented Database Management System (OODBMS)
d) Object-Relational Database Management System (ORDBMS)
22. MySQL is an open-source database management system that is primarily used for:
a) Handling unstructured and semi-structured data
b) Storing and managing large-scale big data
c) Managing complex and interconnected data objects
d) Storing and managing structured data with tables
23. What language is commonly used to interact with MySQL databases for querying and managing
data?
a) PHP
b) C++
c) Java
d) SQL
Answer: d) SQL
24. MySQL is known for its performance and scalability, making it suitable for applications with:
a) Low concurrency and data volume
b) High concurrency and data volume
c) Minimal security requirements
d) No data backup requirements
26. Which operating systems are compatible with MySQL database software?
a) Windows and macOS only
b) macOS and Linux only
c) Windows and Linux only
d) Windows, macOS, and Linux
Answer: d) C
Answer: d) MySQL AB
31. MySQL Monitor is a command-line client tool that allows users to:
a) Perform complex data analysis using advanced statistical functions
b) Monitor the server performance and track resource utilization
c) Connect to the database and execute SQL queries interactively
d) Manage user permissions and access control for the database
32. What is the main purpose of using MySQL Shell as a client tool?
a) To perform backups and data restores
b) To manage server configurations and settings
c) To monitor real-time database performance metrics
d) To interact with the database using JavaScript and Python scripting
Answer: d) To interact with the database using JavaScript and Python scripting
33. MySQL Workbench is a visual database design tool that allows users to:
a) Execute SQL queries and commands in a command-line interface
b) Monitor and optimize server performance for large-scale applications
c) Design, model, and create database schemas and tables graphically
d) Analyze and visualize database performance metrics and query execution plans
Answer: c) Design, model, and create database schemas and tables graphically
34. What are the advantages of using MySQL Workbench for database design?
a) It provides real-time monitoring of server performance.
b) It allows users to write and execute complex SQL queries.
c) It enables users to create and edit database schemas visually.
d) It supports JavaScript and Python scripting for automation.
35. Which MySQL client tool is most suitable for database administrators and developers who prefer a
command-line interface for querying and managing the database?
a) MySQL Monitor
b) MySQL Shell
c) MySQL Workbench
d) MySQL Connector/NET
36. MySQL Workbench provides a visual representation of database schema design through:
a) Entity-Relationship Diagram (ERD)
b) Data Flow Diagram (DFD)
c) Class Diagram
d) Sequence Diagram
37. MySQL Monitor allows users to connect to the MySQL server using:
a) HTTP protocol
b) FTP protocol
c) Telnet protocol
d) MySQL client protocol
39. MySQL Shell is a versatile client tool that provides access to MySQL through various interfaces,
including:
a) Command-line interface (CLI) and REST API
b) Command-line interface (CLI) and Web interface
c) Command-line interface (CLI) and graphical user interface (GUI)
d) Web interface and graphical user interface (GUI)
40. What does the MySQL Workbench performance dashboard provide to users?
a) A visual representation of database schema
42. Which data model represents the overall view of the entire database without concerning the
implementation details?
a) Conceptual data model
b) Logical data model
c) Physical data model
d) Hierarchical data model
43. The logical data model describes the database structure in terms of:
a) Tables, columns, and data types
b) Entity-relationship diagrams (ERD)
c) The physical layout of data on storage devices
d) High-level user views of the database
44. What is the primary difference between the logical and physical data models?
a) Logical data models use graphical representation, while physical data models use text-based
representation.
b) Logical data models focus on user views, while physical data models focus on data storage and
access.
c) Logical data models are used by developers, while physical data models are used by end-users.
d) Logical data models are used for conceptual planning, while physical data models are used for data
analysis.
Answer: b) Logical data models focus on user views, while physical data models focus on data storage
and access.
45. Which data model represents the actual implementation of the database, including storage
structures and access methods?
a) Conceptual data model
b) Logical data model
c) Physical data model
d) Object-oriented data model
46. The conceptual data model is usually represented using which type of diagram?
a) Entity-Relationship Diagram (ERD)
b) Data Flow Diagram (DFD)
c) Class Diagram
d) Sequence Diagram
Answer: c) Objects
48. Which data model is used to create a blueprint for the actual database implementation, including
database tables, indexes, and constraints?
a) Conceptual data model
b) Logical data model
c) Physical data model
d) Object-oriented data model
50. Which data model defines the overall structure of data in the database and includes entities,
attributes, and relationships between entities?
a) Conceptual data model
b) Logical data model
c) Physical data model
d) Hierarchical data model
56. Which cardinality notation in an ERD indicates that an entity must have a corresponding related
entity?
a) (0,1)
b) (1,1)
c) (1,N)
d) (N,N)
Answer: b) (1,1)
57. In an ERD, what does the "zero or one" (0,1) cardinality notation signify?
a) An entity can have zero or one related entities
b) An entity must have exactly one related entity
c) An entity can have many related entities
d) An entity can have zero or many related entities
62. Which rule states that the data in the database must be presented to users in a logical and easily
understandable form?
a) Rule 0
b) Rule 1
c) Rule 2
d) Rule 3
Answer: b) Rule 1
63. According to Codd's rules, the capability of handling multiple users and concurrent transactions is
addressed by which rule?
a) Rule 3
b) Rule 4
c) Rule 5
d) Rule 6
Answer: d) Rule 6
64. Which rule states that changes to the database structure must be performed using the same
relational language used to access the database?
a) Rule 7
b) Rule 8
c) Rule 9
d) Rule 10
Answer: c) Rule 9
65. Codd's rule that ensures that each value in a relational database is guaranteed to be accessible by
using a combination of table name, primary key value, and column name is:
a) Rule 0
b) Rule 1
c) Rule 2
d) Rule 3
Answer: a) Rule 0
66. According to Codd's rules, a relational database management system (RDBMS) must provide a
declarative query language. Which rule addresses this requirement?
a) Rule 5
b) Rule 6
c) Rule 7
d) Rule 8
Answer: c) Rule 7
67. Which of Codd's rules addresses the ability to uniquely identify each row in a relational table using
a primary key?
a) Rule 5
b) Rule 6
c) Rule 7
d) Rule 8
Answer: a) Rule 5
68. According to Codd's rules, which rule ensures that the database management system must provide
facilities to define integrity constraints?
a) Rule 2
b) Rule 3
c) Rule 4
d) Rule 9
Answer: c) Rule 4
69. Codd's rule that requires support for set-level, or non-procedural, manipulation of data is:
a) Rule 7
b) Rule 8
c) Rule 9
d) Rule 10
Answer: b) Rule 8
70. According to Codd's rules, which rule addresses the ability to access and manipulate the data in a
database using a high-level query language?
a) Rule 4
b) Rule 5
c) Rule 6
d) Rule 7
Answer: d) Rule 7
73. Which type of SQL statement is used to retrieve data from a database?
a) DDL (Data Definition Language)
b) DML (Data Manipulation Language)
c) DCL (Data Control Language)
d) TCL (Transaction Control Language)
74. SQL is a:
a) Case-sensitive language
b) Case-insensitive language
c) Both case-sensitive and case-insensitive language, depending on the database system
d) None of the above
Answer: c) Both case-sensitive and case-insensitive language, depending on the database system
75. Which SQL statement is used to insert data into a database table?
a) SELECT
b) UPDATE
c) DELETE
d) INSERT
Answer: d) INSERT
77. Which SQL statement is used to update existing records in a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: c) UPDATE
78. The SQL statement "DELETE FROM orders WHERE order_status = 'CANCELLED';" will:
a) Delete all orders from the "orders" table
b) Delete orders with the status "CANCELLED" from the "orders" table
c) Delete the "orders" table from the database
d) Delete the database itself
Answer: b) Delete orders with the status "CANCELLED" from the "orders" table
Answer: d) The user specifies what data to retrieve, and the database management system figures out
how to retrieve it
Answer: b) CREATE
84. Which SQL category is responsible for committing or rolling back transactions in the database?
a) Data Definition Language (DDL)
b) Data Manipulation Language (DML)
c) Data Control Language (DCL)
d) Transaction Control Language (TCL)
85. In SQL, which command is used to grant specific privileges to a user or role?
a) CREATE
b) UPDATE
c) GRANT
d) ALTER
Answer: c) GRANT
86. Which SQL category is used for creating, altering, and dropping database objects such as tables and
indexes?
a) Data Definition Language (DDL)
b) Data Manipulation Language (DML)
c
87. Which SQL command is used to revoke previously granted privileges from a user or role?
a) REVOKE
b) DELETE
c) ALTER
d) DROP
Answer: a) REVOKE
88. Which SQL category is responsible for querying and retrieving data from the database?
a) Data Definition Language (DDL)
b) Data Manipulation Language (DML)
c) Data Control Language (DCL)
d) Transaction Control Language (TCL)
Answer: b) CREATE
Answer: c) The dependence of one attribute on another within the same table
94. Which type of functional dependency implies that a non-key attribute is dependent on the entire
primary key?
a) Partial dependency
b) Full dependency
c) Transitive dependency
d) Composite dependency
95. Data anomalies, such as update anomalies, are minimized through the process of:
a) Data modeling
b) Indexing
c) Data redundancy
d) Normalization
Answer: d) Normalization
98. Which type of functional dependency occurs when a non-key attribute depends on only part of the
primary key?
a) Full dependency
b) Partial dependency
c) Transitive dependency
d) Composite dependency
100. Which type of functional dependency occurs when a non-key attribute depends on another non-
key attribute in the same table?
a) Full dependency
b) Partial dependency
c) Transitive dependency
d) Composite dependency
103. The main reason for the need for normalization is:
a) To increase data redundancy for better data retrieval
b) To allow easy data manipulation using DDL commands
c) To reduce data anomalies and update inconsistencies
d) To simplify complex data structures for end-users
104. Which normal form ensures that each attribute in a table is dependent only on the primary key and
not on any other non-key attributes?
a) First Normal Form (1NF)
b) Second Normal Form (2NF)
c) Third Normal Form (3NF)
d) Boyce-Codd Normal Form (BCNF)
Answer: a) First Normal Form (1NF)
106. In which normal form is a database table not allowed to have partial dependencies?
a) First Normal Form (1NF)
b) Second Normal Form (2NF)
c) Third Normal Form (3NF)
d) Boyce-Codd Normal Form (BCNF)
107. The process of normalization involves dividing a database into smaller, well-organized tables to:
a) Increase data redundancy
b) Improve data access speed
c) Reduce data integrity
d) Minimize data anomalies and inconsistencies
108. Which normal form allows a database table to have dependencies on a candidate key other than
the primary key?
a) First Normal Form (1NF)
b) Second Normal Form (2NF)
c) Third Normal Form (3NF)
d) Boyce-Codd Normal Form (BCNF)
109. In which normal form is a database table not allowed to have transitive dependencies?
a) First Normal Form (1NF)
b) Second Normal Form (2NF)
c) Third Normal Form (3NF)
d) Boyce-Codd Normal Form (BCNF)
110. Normalization divides a large database into multiple smaller tables to:
a) Increase data redundancy
b) Improve data integrity
c) Simplify data retrieval
d) Introduce data anomalies
**3.3 Normal Forms (1st NF, 2nd NF, 3rd NF, BCNF) with examples**
112. Second Normal Form (2NF) is achieved when a table is in 1NF, and:
a) All attributes are dependent on the primary key
b) The table has no duplicate records
c) The table has a single composite key
d) All attributes are dependent on each other
113. Third Normal Form (3NF) is achieved when a table is in 2NF, and:
a) All attributes are dependent on the primary key
b) The table has no duplicate records
c) There are no transitive dependencies between non-key attributes
d) The table has a single composite key
114. Boyce-Codd Normal Form (BCNF) is achieved when a table is in 3NF, and:
a) All attributes are dependent on the primary key
b) The table has no duplicate records
c) There are no partial dependencies between non-key
attributes
d) The table has a single composite key
117. Consider a table "Orders" with attributes (Order_ID, Customer_ID, Product_ID, Product_Name,
Customer_Name). To be in 1NF, the table should:
a) Have no duplicate records
b) Have atomic values in each attribute
c) Store data about customers and products in separate tables
d) Have all attributes dependent on the Order_ID only
121. Fourth Normal Form (4NF) is achieved when a table is in BCNF, and:
a) There are no partial dependencies between non-key attributes
b) There are no transitive dependencies between non-key attributes
c) The table has no duplicate records
d) There are no multi-valued dependencies between non-key attributes
122. Which normal form deals with multi-valued dependencies between non-key attributes?
a) First Normal Form (1NF)
b) Second Normal Form (2NF)
c) Third Normal Form (3NF)
d) Fourth Normal Form (4NF)
123. Fifth Normal Form (5NF), also known as Project-Join Normal Form (PJNF), is achieved when a
table is in 4NF, and:
a) There are no partial dependencies between non-key attributes
b) There are no transitive dependencies between non-key attributes
c) The table has no duplicate records
d) There are no join dependencies between multi-valued attributes
124. The process of normalizing a database into higher normal forms helps to:
a) Introduce data anomalies and inconsistencies
b) Increase data redundancy for better data retrieval
c) Eliminate data duplication and improve data integrity
d) Simplify complex data structures for end-users
125. Fourth Normal Form (4NF) deals with the elimination of:
a) Data anomalies and inconsistencies
b) Duplicate records in a table
c) Partial dependencies between non-key attributes
d) Transitive dependencies between non-key attributes
127. Which normal form deals with the elimination of join dependencies between multi-valued
attributes?
a) First Normal Form (1NF)
b) Second Normal Form (2NF)
c) Third Normal Form (3NF)
d) Fifth Normal Form (5NF)
130. The main objective of normalizing a database to higher normal forms is to:
a) Increase data redundancy for better data retrieval
b) Simplify complex data structures for end-users
c) Improve data integrity and minimize data anomalies
d) Reduce the size of the database
131. Which SQL command is used to insert new records into a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: b) INSERT
132. The SQL statement "INSERT INTO employees (emp_id, emp_name, emp_salary) VALUES (101,
'John Doe', 50000);" will:
a) Update the employee record with ID 101
b) Delete the employee record with ID 101
c) Insert a new employee record with ID 101, name 'John Doe', and salary 50000
d) Retrieve the employee record with ID 101
Answer: c) Insert a new employee record with ID 101, name 'John Doe', and salary 50000
133. Which SQL command is used to modify existing records in a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: c) UPDATE
134. The SQL statement "UPDATE products SET quantity = 100 WHERE product_id = 123;" will:
a) Insert a new product record with ID 123 and quantity 100
b) Delete the product record with ID 123
c) Update the quantity of the product with ID 123 to 100
d) Retrieve the product record with ID 123
135. Which SQL command is used to remove records from a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: d) DELETE
136. The SQL statement "DELETE FROM customers WHERE customer_id = 101;" will
:
a) Insert a new customer record with ID 101
b) Update the customer record with ID 101
c) Delete the customer record with ID 101
d) Retrieve the customer record with ID 101
138. Which SQL command is used to modify data in multiple rows of a table based on a condition?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: c) UPDATE
139. The SQL statement "DELETE FROM orders WHERE order_status = 'cancelled';" will:
a) Insert new orders with the status 'cancelled'
b) Update the status of all orders to 'cancelled'
c) Delete all orders with the status 'cancelled'
d) Retrieve orders with the status 'cancelled'
140. Which SQL command is used to retrieve data from a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: a) SELECT
141. The SQL statement "SELECT * FROM employees WHERE department = 'HR';" will:
a) Insert a new employee record with department 'HR'
b) Update the department of all employees to 'HR'
c) Delete all employees from the department 'HR'
d) Retrieve all employee records from the department 'HR'
143. Which SQL command is used to add new rows to a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: b) INSERT
144. The SQL statement "UPDATE customers SET balance = 1000 WHERE customer_id = 101;" will:
a) Insert a new customer record with ID 101 and balance 1000
b) Update the balance of the customer with ID 101 to 1000
c) Delete the customer record with ID 101
d) Retrieve the customer record with ID 101
145. Which SQL command is used to remove rows from a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: d) DELETE
146. The SQL statement "DELETE FROM products WHERE product_id = 123;" will:
a) Insert a new product record with ID 123
b) Update the product record with ID 123
c) Delete the product record with ID 123
d) Retrieve the product record with ID 123
148. The SQL statement "UPDATE employees SET salary = 60000 WHERE department = 'HR';" will:
a) Insert a new employee record with salary 60000 in the HR department
b) Update the salary of all employees in the HR department to 60000
c) Delete all employees from the HR department
d) Retrieve employees with a salary of 60000 in the HR department
150. Which SQL command is used to retrieve data from a database table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: a) SELECT
Lecture 4: MySQL Data Types and Query Operations
**4.1 MySQL Data Types**
151. Which MySQL data type is used to store whole numbers without a fractional part?
a) VARCHAR
b) INT
c) FLOAT
d) DATE
Answer: b) INT
153. Which MySQL data type is used to store date and time values?
a) VARCHAR
b) INT
c) FLOAT
d) DATE
Answer: d) DATE
155. Which MySQL data type is used to store fixed-length character strings?
a) VARCHAR
b) CHAR
c) TEXT
d) INT
Answer: b) CHAR
157. Which MySQL data type is used to store a large number with many decimal places?
a) DECIMAL
b) INT
c) FLOAT
d) DATE
Answer: a) DECIMAL
158. The MySQL data type ENUM is used to store:
a) Whole numbers without a fractional part
b) Floating-point numbers with decimal values
c) Date and time values
d) A list of predefined allowed values
Answer: d) DECIMAL
**4.2 Database Constraints (Primary Key, Unique, Not Null, Foreign Key, Default, Check*)**
Answer: c) Defines a column or set of columns that uniquely identify each row in the table
Answer: d) Assigns a default value to a column when no value is specified during insertion
167. The PRIMARY KEY and UNIQUE constraints are used to enforce:
a) Referential integrity
b) Entity integrity
c) Domain integrity
d) Check integrity
Answer
178. The GROUP BY clause is used in conjunction with which SQL function?
a) COUNT()
b) SUM()
c) AVG()
d) MAX()
Answer: a) COUNT()
179. The HAVING clause is used in conjunction with which SQL function?
a) COUNT()
b) SUM()
c) AVG()
d) MAX()
Answer: a) COUNT()
180. The SQL statement "SELECT department, COUNT(*) FROM employees GROUP BY
department;" will:
a) Retrieve the total number of employees in each department
b) Calculate the average salary of employees in each department
c) Retrieve the employee records from the HR department
d) Group employees by department and display the department names
184. The SQL statement "SELECT * FROM products WHERE product_name LIKE 'App%';" will
retrieve:
a) All products with names starting with 'App'
b) All products with names containing 'App'
c) All products with names ending with 'App'
d) All products with names exactly 'App'
185. The SQL statement "SELECT DISTINCT department FROM employees;" will retrieve:
a) All employees from the HR department
b) The total number of employees in each department
c) A list of unique department names
d) The average salary of employees in each department
186. The SQL statement "SELECT product_name, price FROM products ORDER BY price DESC;"
will retrieve:
a) Product names and prices in ascending order of price
b) Product names and prices in descending order of price
c) All products with prices greater than a specific value
d) All products with prices less than a specific value
Answer: b) Product names and prices in descending order of price
187. The SQL statement "SELECT * FROM orders WHERE order_date BETWEEN '2022-01-01'
AND '2022-12-31';" will retrieve:
a) All orders placed on January 1, 2022
b) All orders placed in the year 2022
c) All orders placed between January 1, 2022, and December 31, 2022
d) All orders placed before January 1, 2022
Answer: c) All orders placed between January 1, 2022, and December 31, 2022
188. The SQL statement "SELECT * FROM customers WHERE city IS NULL;" will retrieve:
a) All customers with a NULL city value
b) All customers with a non-NULL city value
c) All customers from a specific city
d) All customers with a NULL or empty city value
189. The SQL statement "SELECT product_name FROM products WHERE product_id NOT IN (1001,
1002, 1003);" will retrieve:
a) All products with product IDs 1001, 1002, or 1003
b) All products with product IDs other than 1001, 1002, or 1003
c) All products with a NULL product ID
d) All products with a product ID greater than 1003
Answer: b) All products with product IDs other than 1001, 1002, or 1003
190. The SQL statement "SELECT * FROM customers WHERE phone IS NOT NULL;" will retrieve:
a) All customers with a NULL phone value
b) All customers with a non-NULL phone value
c) All customers with a specific phone number
d) All customers with a phone number containing a specific pattern
**4.5 BETWEEN… AND Operators, Comparing Nulls (IS NULL/IS NOT NULL), IN/NOT IN**
192. The SQL statement "SELECT * FROM employees WHERE age BETWEEN 25 AND 40;" will
retrieve:
a) All employees older than 25 and younger than 40
b) All employees with an age of 25 or 40
c) All employees with an age outside the range of 25 to 40
d) All employees with an age equal to 25 or 40
194. The SQL statement "SELECT * FROM products WHERE category IS NULL;" will retrieve:
a) All products with a category value of NULL
b) All products with a non-NULL category value
c) All products with a specific category value
d) All products with a category value containing a specific pattern
Answer: a) All products with a category value of NULL
195. The SQL statement "SELECT * FROM customers WHERE city IS NOT NULL;" will retrieve:
a) All customers with a NULL city value
b) All customers with a non-NULL city value
c) All customers with a specific city
d) All customers with a city containing a specific pattern
Answer: b) All customers with a non-NULL city value
197. The SQL statement "SELECT * FROM employees WHERE department IN ('HR', 'Finance');" will
retrieve:
a) All employees from the HR department or the Finance department
b) All employees from departments other than HR and Finance
c) All employees with a NULL department
d) All employees with a department containing 'HR' or 'Finance'
Answer: a) All employees from the HR department or the Finance department
199. The SQL statement "SELECT * FROM products WHERE category NOT IN ('Electronics',
'Clothing');" will retrieve:
a) All products with a category other than 'Electronics' or 'Clothing'
b) All products with a category of 'Electronics' or 'Clothing'
c) All products with a NULL category
d) All products with a category containing 'Electronics' or 'Clothing'
Answer: a) All products with a category other than 'Electronics' or 'Clothing'
200. The SQL statement "SELECT * FROM customers WHERE phone NOT IN ('123-456-7890', '987-
654-3210');" will retrieve:
a) All customers with a phone number other than '123-456-7890' or '987-654-3210'
b) All customers with a phone number of '123-456-7890' or '987-654-3210'
c) All customers with a NULL phone number
d) All customers with a phone number containing '123' or '987'
Answer: a) All customers with a phone number other than '123-456-7890' or '987-654-3210'
Lecture 5: Relational Algebra and Joins
1. Which relational algebra operation is used to select rows that satisfy a given condition?
a) Union
b) Projection
c) Selection
d) Intersect
Answer: c) Selection
2. Which relational algebra operation is used to combine the results of two queries, removing
duplicates?
a) Union
b) Intersection
c) Minus
d) Cartesian product
Answer: a) Union
3. The relational algebra operation that selects specific columns from a table is called:
a) Join
b) Projection
c) Union
d) Cross product
Answer: b) Projection
5. The result of a Cartesian product between two tables with m and n rows, respectively, will have:
a) m * n rows
b) m + n rows
c) m - n rows
d) n - m rows
Answer: a) m * n rows
8. Which relational algebra operation combines rows from two tables, including duplicates?
a) Union
b) Intersection
c) Join
d) Cartesian product
Answer: a) Union
9. Which relational algebra operation is used to combine the results of two queries, including duplicates?
a) Union
b) Intersection
c) Minus
d) Join
Answer: a) Union
10. The primary purpose of the CROSS/CARTESIAN product in relational algebra is to:
a) Select specific columns from two tables
b) Combine rows from two tables, excluding duplicates
c) Combine rows from two tables, including duplicates
d) Find the intersection of two sets
Answer: c) Combine rows from two tables, including duplicates
**5.2 Joins**
2. Which type of join returns only the matching rows from both tables?
a) Inner join
b) Outer join
c) Natural join
d) Cross join
Answer: a) Inner join
3. A join that returns all rows from both tables and fills in NULL values for non-matching rows is
called:
a) Inner join
b) Outer join
c) Natural join
d) Cross join
Answer: b) Outer join
5. Which join type combines all rows from both tables, but returns NULL for non-matching rows?
a) Inner join
b) Outer join
c) Natural join
d) Cross join
Answer: b) Outer join
6. A join that combines rows from two tables, including non-matching rows, is called:
a) Inner join
b) Outer join
c) Natural join
d) Cross join
Answer: b) Outer join
7. The CROSS join is also known as:
a) Cartesian join
b) Equi join
c) Inner join
d) Outer join
Answer: a) Cartesian join
8. An INNER join is equivalent to which other type of join when a WHERE clause is used to define the
join condition?
a) Natural join
b) Equi join
c) Outer join
d) Cross join
Answer: b) Equi join
9. Which join type returns only the rows from both tables that meet the join condition?
a) Inner join
b) Outer join
c) Natural join
d) Cross join
Answer: a) Inner join
10. In an outer join, the non-matching rows have NULL values in the columns from which table?
a) Only the left table
b) Only the right table
c) Both left and right tables
d) None of the above
Answer: c) Both left and right tables
2. Which SQL join keyword returns all rows from both tables, including non-matching rows?
a) INNER JOIN
b) OUTER JOIN
c) NATURAL JOIN
d) CROSS JOIN
Answer: b) OUTER JOIN
3. In SQL, the condition for an equi join is typically specified using the:
a) ON keyword
b) USING keyword
c) WHERE clause
d) JOIN keyword
Answer: a) ON keyword
6. Which SQL join keyword returns only the matching rows from both tables?
a) INNER JOIN
b) OUTER JOIN
c) NATURAL JOIN
d) CROSS JOIN
Answer: a) INNER JOIN
7. To perform a CROSS join in SQL, you would use the following syntax:
a) SELECT * FROM table1 CROSS JOIN table2;
b)
9. Which SQL join keyword combines all rows from both tables but includes NULL for non-matching
rows?
a) INNER JOIN
b) OUTER JOIN
c) NATURAL JOIN
d) CROSS JOIN
Answer: b) OUTER JOIN
10. In SQL, the USING keyword is used in which type of join to specify the join condition based on a
specific column?
a) INNER JOIN
b) OUTER JOIN
c) NATURAL JOIN
d) CROSS JOIN
Answer: c) NATURAL JOIN
1. When copying a table structure (without data) in SQL, which keyword is commonly used?
a) CREATE
b) INSERT
c) COPY
d) DUPLICATE
Answer: a) CREATE
2. The SQL statement for copying a table structure without copying data is:
a) DUPLICATE TABLE new_table AS
b) CREATE new_table LIKE original_table;
c) CREATE new_table AS SELECT * FROM original_table;
d) INSERT INTO new_table SELECT * FROM original_table;
Answer: c) CREATE new_table AS SELECT * FROM original_table;
3. To copy the structure and data of a table to a new table in SQL, you would use:
a) DUPLICATE TABLE new_table AS SELECT * FROM original_table;
b) CREATE new_table AS SELECT * FROM original_table;
c) INSERT new_table SELECT * FROM original_table;
d) CREATE new_table LIKE original_table;
Answer: b) CREATE new_table AS SELECT * FROM original_table;
4. In SQL, how can you copy the structure of a table without copying the data?
a) CREATE new_table AS SELECT * FROM original_table WHERE 1=0;
b) INSERT INTO new_table SELECT * FROM original_table WHERE 1=0;
c) CREATE new_table LIKE original_table;
d) DUPLICATE TABLE new_table AS SELECT * FROM original_table WHERE 1=0;
Answer: c) CREATE new_table LIKE original_table;
5. When copying a table structure and data in SQL, what should you consider to ensure primary key
constraints are also copied?
a) The primary key is automatically copied along with the data.
b) You need to manually define the primary key in the new table.
c) The primary key cannot be copied; it must be recreated in the new table.
d) Primary key constraints are automatically removed during the copy process.
Answer: a) The primary key is automatically copied along with the data.
6. In SQL, which statement copies the data from one table to another?
a) INSERT INTO new_table SELECT * FROM original_table;
b) CREATE new_table AS SELECT * FROM original_table;
c) COPY new_table FROM original_table;
d) UPDATE new_table SET * FROM original_table;
Answer: a) INSERT INTO new_table SELECT * FROM original_table;
8. In SQL, to copy the structure of a table without copying the data, you can use the statement:
a) CREATE new_table LIKE original_table;
b) INSERT new_table SELECT * FROM original_table;
c) DUPLICATE TABLE new_table AS SELECT * FROM original_table;
d) CREATE new_table AS SELECT * FROM original_table WHERE 1=0;
Answer: a) CREATE new_table LIKE original_table;
9. Which SQL statement copies the structure and data of a table to a new table, including the auto-
incremented values?
a) CREATE new_table AS SELECT * FROM original_table;
b) INSERT new_table SELECT * FROM original_table;
c) CREATE new_table LIKE original_table;
d) DUPLICATE TABLE new_table AS SELECT * FROM original_table;
Answer: b) INSERT new_table SELECT * FROM original_table;
7. Which SQL keyword is used to filter results based on the existence of a subquery's result?
a) IN
b) EXISTS
c) ALL
d) UNION
Answer: b) EXISTS
7. What happens when a user is granted the GRANT OPTION privilege in SQL?
a) The user is granted all privileges on all tables in the database
b) The user is granted the ability to grant or revoke privileges to other users
c) The user is granted administrative privileges on the database
d) The user is granted the ability to create new tables in the database
Answer: b) The user is granted the ability to grant or revoke privileges to other users
8. The main purpose of using the GRANT OPTION privilege in SQL is to:
a) Allow a user to create a new database
b) Allow a user to modify the database schema
c) Allow a user to grant or revoke privileges to other users
d) Allow a user to delete tables from the database
Answer: c) Allow a user to grant or revoke privileges to other users
9. What is the effect of using the REVOKE command on a user's privileges in SQL?
a) The user's privileges are assigned to another user
b) The user's privileges are removed permanently
c) The user's privileges are temporarily suspended
d) The user's privileges are replaced with default privileges
Answer: b) The user's privileges are removed permanently
10. Which SQL command is used to grant privileges on specific database objects, such as tables or
views?
a) GRANT OBJECT
b) GRANT ALL PRIVILEGES
c) GRANT TABLE
d) GRANT SELECT, INSERT, UPDATE, DELETE
Answer: d) GRANT SELECT, INSERT, UPDATE, DELETE
6. What happens when data in the underlying tables of a view is modified in SQL?
a) The view is automatically updated with the new data
b) The view is deleted and needs to be recreated
c) The view remains unchanged until explicitly refreshed
d) The view is automatically refreshed to include the new data
Answer: a) The view is automatically updated with the new data
7. Which type of view in SQL allows you to perform data manipulation operations?
a) Simple view
b) Complex view
c) Updatable view
d) Non-updatable view
Answer: c) Updatable view
9. What is the main difference between a simple view and a complex view in SQL?
a) A simple view cannot be queried directly, while a complex view can.
b) A simple view is created using multiple SELECT statements, while a complex view uses a single
SELECT statement.
c) A simple view refers to only one table, while a complex view may refer to multiple tables.
d) A simple view cannot be updated, while a complex view can.
Answer: c) A simple view refers to only one table, while a complex view may refer to multiple tables.
3. Which type of index in a database ensures a unique value for each row?
a) Primary index
b) Clustered index
c) Non-clustered index
d) Composite index
Answer: a) Primary index
2. Which ACID property ensures that either all the operations in a transaction are executed or none of
them are?
a) Atomicity
b) Consistency
c) Isolation
d) Durability
Answer: a) Atomicity
a) Data modifications are not visible to other transactions until the transaction is committed
b) All operations in a transaction are executed successfully
c) Transactions are executed concurrently without interfering with each other
d) The database remains in a consistent state after a transaction is completed
Answer: c) Transactions are executed concurrently without interfering with each other
8. Which ACID property ensures that once a transaction is committed, its changes are permanent and
will survive any subsequent failures?
a) Atomicity
b) Consistency
c) Isolation
d) Durability
Answer: d) Durability
1. In the MySQL database, which storage engine is known for providing ACID properties and is well-
suited for transactional operations?
a) InnoDB
b) MyISAM
c) MEMORY
d) ARCHIVE
Answer: a) InnoDB
2. Which storage engine in MySQL is best known for its performance in read-intensive operations?
a) InnoDB
b) MyISAM
c) MEMORY
d) ARCHIVE
Answer: b) MyISAM
4. The InnoDB storage engine in MySQL is known for its support for:
a) Full-text search indexes
b) Foreign key constraints and transactions
c) Data compression and encryption
d) Clustered indexes
Answer: b) Foreign key constraints and transactions
6. The MyISAM storage engine in MySQL is known for its support for:
a) Foreign key constraints and transactions
b) Full-text search indexes
c) Data compression and encryption
d) Clustered indexes
Answer: b) Full-text search indexes
7. Which storage engine in MySQL is optimized for write-intensive operations and is useful for
logging applications?
a) InnoDB
b) MyISAM
c) MEMORY
d) ARCHIVE
Answer: d) ARCHIVE
9. Which MySQL storage engine is best suited for simple and non-transactional read operations?
a) InnoDB
b) MyISAM
c) MEMORY
d) CSV
Answer: b) MyISAM
10. The MEMORY storage engine in MySQL is known for its support for:
a) Full-text search indexes
b) Foreign key constraints and transactions
c) Data compression and encryption
d) Temporary or in-memory tables
Answer: d) Temporary or in-memory tables
Lecture 8: Introduction to MySQL Programming and Stored Procedures
1. Which MySQL program is used for interacting with the MySQL server and executing SQL queries
interactively?
a) mysqldump
b) mysqlimport
c) mysql
d) mysqlshow
Answer: c) mysql
4. Which MySQL program is used for importing data from an external file into a MySQL database?
a) mysqlimport
b) mysqldump
c) mysqlshow
d) mysql
Answer: a) mysqlimport
8. Which MySQL program is used for exporting data from MySQL tables to an external file?
a) mysqldump
b) mysqlimport
c) mysqlshow
d) SELECT INTO OUTFILE
Answer: d) SELECT INTO OUTFILE
9. The MySQL program "mysqladmin" is typically used for:
a) Importing data into a MySQL database
b) Displaying the structure of a database
c) Managing the MySQL server and performing administrative tasks
d) Executing SQL queries interactively
Answer: c) Managing the MySQL server and performing administrative tasks
4. What is one of the benefits of using stored procedures for database operations?
a) Increased database size
b) Improved data security
c) Slower execution of queries
d) Limited access to database objects
Answer: b) Improved data security
9. What is one of the advantages of using stored procedures for database operations?
a) Increased database size
b) Improved data security
c) Slower execution of queries
d) Inability to reuse code
Answer: b) Improved data security
1. In a stored procedure
4. Which parameter type is used to pass data into a stored procedure in MySQL?
a) IN
b) OUT
c) INOUT
d) INPUT
Answer: a) IN
8. In a stored procedure, which parameter type is used when data needs to be both passed into and
returned from the procedure?
a) IN
b) OUT
c) INOUT
d) INPUT
Answer: c) INOUT
1. In MySQL, which flow control statement is used to repeatedly execute a block of code as long as
a specified condition is true?
a) LOOP
b) WHILE
c) REPEAT
d) IF
Answer: b) WHILE
3. What is the primary difference between the WHILE statement and the REPEAT statement in
MySQL?
a) The WHILE statement executes the loop as long as the condition is false, while the REPEAT
statement executes the loop as long as the condition is true.
b) The WHILE statement evaluates the condition at the beginning of the loop, while the REPEAT
statement evaluates the condition at the end of the loop.
c) The WHILE statement is used for nested loops, while the REPEAT statement is used for single-
level loops.
d) There is no difference between the WHILE and REPEAT statements; they are interchangeable.
Answer: b) The WHILE statement evaluates the condition at the beginning of the loop, while the
REPEAT statement evaluates the condition at the end of the loop.
5. Which flow control statement in MySQL is best suited for cases where you want the code block to
be executed at least once, regardless of the condition?
a) LOOP
b) WHILE
c) REPEAT
d) IF
Answer: c) REPEAT
7. Which flow control statement in MySQL is best suited for cases where the number of loop
iterations is known beforehand?
a) LOOP
b) WHILE
c) REPEAT
d) IF
Answer: a) LOOP
8. The primary use of the WHILE statement in MySQL is to:
a) Execute a block of code repeatedly until a specified condition is met
b) Perform a single iteration of a loop
c) Exit a loop prematurely
d) Evaluate multiple conditions and execute corresponding code blocks
Answer: a) Execute a block of code repeatedly until a specified condition is met
9. In MySQL, which flow control statement is used to terminate a loop prematurely based on a
specified condition?
a) LOOP
b) WHILE
c) REPEAT
d) LEAVE
Answer: d) LEAVE
10. Which flow control statement in MySQL is used to label a loop and provide an exit point for the
loop using the LEAVE statement?
a) LOOP
b) WHILE
c) REPEAT
d) BEGIN...END
Answer: d) BEGIN...END
1. In MySQL, can flow control statements like LOOP, WHILE, and REPEAT be used in stored
procedures or functions?
a) Yes, they can only be used in stored procedures.
b) Yes, they can only be used in functions.
c) No, flow control statements cannot be used in stored procedures or functions.
d) Yes, they can be used in both stored procedures and functions.
Answer: d) Yes, they can be used in both stored procedures and functions.
2. What is the main advantage of using flow control statements in stored procedures or functions?
a) They allow for the declaration of variables within the procedure or function.
b) They provide a way to handle errors and exceptions.
c) They allow for the execution of repetitive code blocks based on certain conditions.
d) They enable the creation of temporary tables for data processing.
Answer: c) They allow for the execution of repetitive code blocks based on certain conditions.
3. When using flow control statements in a stored procedure, what determines the termination of a
loop?
a) The number of iterations specified in the LOOP statement
b) The condition specified in the WHILE statement
c) The condition specified in the REPEAT statement
d) The LEAVE statement
Answer: b) The condition specified in the WHILE statement
4. Can flow control statements in a stored procedure or function be nested within each other?
a) Yes, flow control statements can be nested to create complex control structures.
b) No, flow control statements cannot be nested in MySQL.
c) Only the WHILE and REPEAT statements can be nested, not the LOOP statement.
d) Only the LOOP and WHILE statements can be nested, not the REPEAT statement.
Answer: a) Yes, flow control statements can be nested to create complex control structures.
5. Which of the following statements is true regarding the usage of flow control statements in stored
procedures or functions?
a) Flow control statements can only be used inside a BEGIN...END block.
b) Flow control statements cannot be used in functions, only in stored procedures.
c) Flow control statements cannot be used inside conditional statements like IF.
d) Flow control statements can be used to modify database tables directly.
Answer: a) Flow control statements can only be used inside a BEGIN...END block.
6. Can flow control statements like LOOP, WHILE, and REPEAT be used to manipulate data in the
database directly?
a) Yes, they can directly insert, update, or delete data in the database.
b) No, flow control statements are only used for control flow and cannot directly manipulate data
in the database.
c) Yes, they can be used to create temporary tables for data processing.
d) Yes, they can be used to create indexes on tables.
Answer: b) No, flow control statements are only used for control flow and cannot directly
manipulate data in the database.
7. Which of the following flow control statements is commonly used to handle repetitive tasks in a
stored procedure or function?
a) IF-ELSE-THEN
b) LOOP
c) REPEAT
d) BEGIN...END
Answer: b) LOOP
8. When using flow control statements in a stored procedure, what is required to ensure that the loop
does not run indefinitely?
a) The LEAVE statement
b) The BEGIN...END block
c) A counter variable and an exit condition
d) The RETURN statement
Answer: c) A counter variable and an exit condition
9. Which of the following is an example of using a flow control statement in a stored procedure?
a
10. When using flow control statements in a stored procedure or function, what is important to
consider to avoid potential performance issues?
a) Using the correct data types for variables and parameters
b) Nesting multiple flow control statements
c) Using flow control statements inside conditional statements
d) Avoiding the use of temporary tables
Answer: a) Using the correct data types for variables and parameters
1. In MySQL, which conditional statement is used to execute a block of code only if a specified
condition is true?
a) IF
b) IF-ELSE-THEN
c) SWITCH CASE
d) WHILE
Answer: a) IF
3. What is the primary difference between the IF statement and the IF-ELSE-THEN statement in
MySQL?
a) The IF statement allows for the evaluation of multiple conditions, while the IF-ELSE-THEN
statement evaluates a single condition.
b) The IF statement does not allow for branching, while the IF-ELSE-THEN statement provides a
way to handle multiple cases.
c) The IF statement executes the code block if the condition is true, while the IF-ELSE-THEN
statement executes an alternative block of code if the condition is false.
d) There is no difference between the IF and IF-ELSE-THEN statements; they are interchangeable.
Answer: c) The IF statement executes the code block if the condition is true, while the IF-ELSE-
THEN statement executes an alternative block of code if the condition is false.
5. Which conditional statement in MySQL is best suited for cases where you need to check multiple
conditions and execute different code blocks for each condition?
a) IF
b) IF-ELSE-THEN
c) SWITCH CASE
d) WHILE
Answer: c) SWITCH CASE
8. Which conditional statement in MySQL allows you to check multiple conditions and execute
different code blocks for each condition, similar to a series of IF-ELSE statements?
a) IF
b) IF-ELSE-THEN
c) SWITCH CASE
d) WHILE
Answer: c) SWITCH CASE
9. In the SWITCH CASE statement in MySQL, what happens when a condition is met and its
corresponding code block is executed?
a) The execution continues with the next case statement regardless of whether it matches the
condition.
b) The execution continues with the default code block.
c) The execution jumps to the end of the SWITCH CASE statement.
d) The execution exits the SWITCH CASE statement.
Answer: d) The execution exits the SWITCH CASE statement.
10. Which of the following is an example of using a conditional statement in a stored procedure?
a) Creating a new database schema
b) Inserting data into a table
c) Displaying a list of records from a table based on a specific condition
d) Updating a specific record based on a condition
Answer: c) Displaying a list of records from a table based on a specific condition
(Note: The examples for each type of statement will be provided in pseudocode, as MySQL code
snippets might require a specific database context.)
1. In MySQL, which loop construct is used to continue the next iteration of a loop?
a) ITERATE
b) LEAVE
c) LOOP
d) WHILE
Answer: a) ITERATE
6. When using the ITERATE statement in a loop, what happens when the statement is encountered?
a) The loop continues with the next iteration.
b) The loop terminates immediately.
c) The loop restarts from the beginning.
d) The loop condition is evaluated.
Answer: a) The loop continues with the next iteration.
10. In MySQL, which loop construct is used for executing a block of code repeatedly based on a
specified condition?
a) ITERATE
b) LEAVE
c) LOOP
d) WHILE
Answer: d) WHILE
4. When defining a function in MySQL with parameters, what is required for each parameter?
a) A unique data type
b) A default value
c) A unique name and data type
d) An IN or OUT keyword
Answer: c) A unique name and data type
7. In MySQL, can functions with parameters return different data types based on the provided input?
a) Yes, functions can return different data types for different input values.
b) No, functions must always return the same data type.
c) Only string data types can be returned from functions with parameters.
d) Only numeric data types can be returned from functions with parameters.
Answer: b) No, functions must always return the same data type.
10. Which of the following is true regarding functions with parameters in MySQL?
a) The number of parameters is limited to one per function.
b) Parameters must be passed in a specific order as defined in the function.
c) Parameters must be of the same data type.
d) Parameters must be enclosed in double quotes when calling the function.
Answer: b) Parameters must be passed in a specific order as defined in the function.
**10.3 MySQL Built-in Functions (string, numeric, date, etc.)**
LENGTH()
d) STRLEN()
Answer: c) LENGTH()
7. Which built-in function in MySQL is used to extract the year from a date?
a) YEAR()
b) EXTRACT_YEAR()
c) GET_YEAR()
d) DATE_YEAR()
Answer: a) YEAR()
9. Which built-in function in MySQL is used to calculate the square root of a number?
a) SQRT()
b) SQUARE_ROOT()
c) ROOT()
d) NUM_SQRT()
Answer: a) SQRT()
3. Which type of cursor in MySQL allows the cursor to be scrollable in both forward and backward
directions?
a) SENSITIVE
b) INSENSITIVE
c) SCROLLABLE
d) Nonscrollable
Answer: c) SCROLLABLE
5. Which cursor type in MySQL allows the cursor to be scrollable but only in the forward direction?
a) FORWARD-ONLY
b) SCROLLABLE
c) BACKWARD-ONLY
d) Nonscrollable
Answer: a) FORWARD-ONLY
7. Which type of cursor in MySQL allows the cursor to move forward, but once a row is fetched, it
cannot be fetched again?
a) SENSITIVE
b) INSENSITIVE
c) READ-ONLY
d) Nonscrollable
Answer: d) Nonscrollable
8. When using a cursor in MySQL, what happens when the cursor reaches the end of the result set?
a) The cursor automatically closes and releases the resources.
b) The cursor stops and requires manual closing using the CLOSE statement.
c) The cursor starts from the beginning and fetches the result set again.
d) The cursor prompts the user to choose the next action.
Answer: b) The cursor stops and requires manual closing using the CLOSE statement.
10. Which of the following is true regarding the use of cursors in MySQL?
a) Cursors should be used for all data retrieval operations for better performance.
b) Cursors are the most efficient way to manipulate data in MySQL.
c) Cursors should be avoided whenever possible due to potential performance issues.
d) Cursors can only be used in stored procedures, not in functions.
Answer: c) Cursors should be avoided whenever possible due to potential performance issues.
1. In MySQL, what is the typical real-time use case for using a cursor?
a) Calculating the average of all records in a table
b) Updating a single record in a table
c) Performing complex mathematical calculations
d) Navigating through the result set of a large query and processing each row individually
Answer: d) Navigating through the result set of a large query and processing each row individually
2. When using a cursor in MySQL, what is the common approach to process each row of the result set?
a) Use a loop construct like WHILE or REPEAT.
b)
3. In a real-world scenario, how might a cursor be used in MySQL to process each row of a result set?
a) To insert new records into another table based on certain conditions.
b) To perform a single mathematical calculation on the entire result set.
c) To update all records in the result set simultaneously.
d) To directly delete records from the result set without looping.
Answer: a) To insert new records into another table based on certain conditions.
4. In MySQL, when using a cursor, what happens if the FETCH statement is executed multiple times
without the loop control structure?
a) The cursor automatically closes.
b) The cursor starts fetching rows from the beginning each time.
c) The cursor moves to the next row after each FETCH statement.
d) The cursor throws an error and stops execution.
Answer: c) The cursor moves to the next row after each FETCH statement.
5. What is the primary advantage of using a cursor in MySQL to process a result set?
a) Faster execution compared to using loop constructs.
b) Ability to perform complex mathematical calculations.
c) Simultaneous update of all records in the result set.
d) Memory-efficient storage of the entire result set.
Answer: d) Memory-efficient storage of the entire result set.
6. In a real-time use case, how might a cursor in MySQL be beneficial for a large result set?
a) It allows for faster execution of complex calculations on the entire result set.
b) It prevents other users from accessing the same result set simultaneously.
c) It allows for efficient navigation and processing of each row individually.
d) It automatically indexes the result set for better performance.
Answer: c) It allows for efficient navigation and processing of each row individually.
7. When using a cursor to process a result set in MySQL, what action should be taken after fetching the
last row?
a) Close the cursor manually using the CLOSE statement.
b) Use the BREAK statement to exit the loop.
c) Reset the cursor to the beginning of the result set.
d) Use the STOP statement to halt further execution.
Answer: a) Close the cursor manually using the CLOSE statement.
8. In a real-world scenario, how might a cursor be used in MySQL to update specific rows in a result
set?
a) By using the ITERATE statement to skip unwanted rows during the loop.
b) By directly updating the entire result set without using a loop.
c) By using the LEAVE statement to exit the loop when the update is complete.
d) By using the UPDATE statement to modify the specific rows fetched by the cursor.
Answer: d) By using the UPDATE statement to modify the specific rows fetched by the cursor.
9. In MySQL, when using a cursor to process a result set, what happens if the loop control structure is
not used?
a) The cursor automatically closes after the first row is fetched.
b) The cursor remains open and fetches the entire result set.
c) The cursor returns an error and stops execution.
d) The cursor moves to the next row after each FETCH statement without any iteration.
Answer: d) The cursor moves to the next row after each FETCH statement without any iteration.
10. In a real-time use case, how might a cursor in MySQL be beneficial for a result set with millions of
records?
a) It allows for parallel execution of queries on the same result set.
b) It automatically optimizes the result set for faster processing.
c) It prevents other users from accessing the result set during processing.
d) It fetches and processes rows one at a time, reducing memory consumption.
Answer: d) It fetches and processes rows one at a time, reducing memory consumption.
3. When defining a trigger in MySQL, which keyword is used to specify that the trigger should be
executed after the triggering event occurs?
a) AFTER
b) POST
c) FINISH
d) ON
Answer: a) AFTER
4. In MySQL, what are "NEW" and "OLD" trigger variables used for?
a) To store the values of columns affected by the triggering event
b) To determine the time when the trigger was created
c) To store the previous and current states of the database schema
d) To keep track of the number of triggers defined in the database
Answer: a) To store the values of columns affected by the triggering event
7. When using a BEFORE trigger in MySQL, can the triggering event be canceled or modified?
a) Yes, the triggering event can be canceled or modified within a BEFORE trigger.
b) No, a BEFORE trigger cannot cancel or modify the triggering event.
c) A BEFORE trigger cannot be used in MySQL.
d) A BEFORE trigger can only modify the triggering event, not cancel it.
Answer: a) Yes, the triggering event can be canceled or modified within a BEFORE trigger.
8. In MySQL, can a table have multiple triggers defined for the same event?
a) No, only one trigger per event is allowed for each table.
b) Yes, but the triggers must have different actions.
c) Yes, and the triggers will be executed in the order they were defined.
d) Yes, but the triggers must have different names.
Answer: c) Yes, and the triggers will be
9. In a MySQL trigger, what can be done with the "OLD" trigger variable?
a) It can be modified to change the values of columns in the database.
b) It can be used to retrieve the values of columns before an update or delete operation.
c) It can be used to track the number of rows affected by the trigger.
d) It can be used to retrieve the values of columns after an insert or update operation.
Answer: b) It can be used to retrieve the values of columns before an update or delete operation.
10. In MySQL, what happens if a trigger attempts to modify the table that triggered it?
a) The trigger is executed without any issues.
b) The trigger goes into a suspended state until the table modification is complete.
c) A circular reference error occurs, and the trigger is not executed.
d) A recursive trigger error occurs, and the trigger is aborted.
Answer: d) A recursive trigger error occurs, and the trigger is aborted.
3. In a real-world use case, how might an "AFTER INSERT" trigger be beneficial in MySQL?
a) To calculate the average value of a column after each insert operation.
b) To automatically insert new rows into another table after an insert.
c) To restrict access to the database after new rows are inserted.
d) To create a backup of the entire database after each insert.
Answer: b) To automatically insert new rows into another table after an insert.
7. In a real-world use case, how might a combination of "BEFORE INSERT" and "BEFORE
UPDATE" triggers be utilized in MySQL?
a) To calculate the average of a specific column before inserting new rows or updating existing ones.
b) To prevent any data modification in the table.
c) To generate a unique identifier for each row before an insert or update operation.
d) To retrieve data from another table and update the current table before any modification.
Answer: c) To generate a unique identifier for each row before an insert or update operation.
8. In MySQL, what is a common real-time use for a combination of "AFTER INSERT" and "AFTER
DELETE" triggers?
a) To perform complex mathematical calculations after each insert or delete operation.
b) To calculate the sum of all values in a column and update another table.
c) To automatically insert or delete rows in other tables based on changes in the current table.
d) To prevent any further data modification after insert or delete operations.
Answer: c) To automatically insert or delete rows in other tables based on changes in the current
table.
10. In MySQL, what is a common real-time use for a combination of "BEFORE DELETE" and
"AFTER DELETE" triggers?
a) To calculate the sum of all deleted values in a column.
b) To automatically delete the entire table after a delete operation.
c) To retrieve data from another table and update the current table after the delete operation.
d) To store the deleted rows in a separate backup table before and after deletion.
Answer: d) To store the deleted rows in a separate backup table before and after deletion.
Lecture 11: Error Handling and Exceptions
3. When defining a handler in MySQL, which condition can be specified to catch any unhandled
exception?
a) SQLEXCEPTION
b) SQLWARNING
c) NOT FOUND
d) CONTINUE
Answer: c) NOT FOUND
4. What action can be taken using a handler when a specific condition occurs in a stored procedure?
a) Execute another stored procedure
b) Raise a custom exception
c) Resume execution from a specific point
d) Print an error message and terminate the program
Answer: c) Resume execution from a specific point
5. In MySQL, how can you specify a handler to perform a specific action when a NOT FOUND
condition occurs?
a) SET HANDLER FOR NOT FOUND
b) SET HANDLER FOR SQLWARNING
c) SET HANDLER FOR SQLEXCEPTION
d) SET HANDLER FOR CONDITION NOT FOUND
Answer: d) SET HANDLER FOR CONDITION NOT FOUND
6. When a handler is defined in a stored procedure or function, where does the execution flow move
when the specified condition occurs?
a) To the end of the program
b) To the beginning of the program
c) To a specific label or statement within the program
d) To another stored procedure or function
Answer: c) To a specific label or statement within the program
7. What happens if a condition occurs in a stored procedure or function, but no handler is defined to
catch that condition?
a) The program terminates with an error message.
b) The program continues execution normally.
c) The database automatically creates a default handler for the condition.
d) The program waits indefinitely for a handler to be defined externally.
Answer: a) The program terminates with an error message.
8. In MySQL, which of the following handler actions can be used to exit a loop prematurely when a
specific condition is met?
a) CONTINUE
b) EXIT
c) RESUME
d) LEAVE
Answer: d) LEAVE
10. What is the purpose of using a handler action like CONTINUE in MySQL?
a) To execute another stored procedure or function when a condition occurs
b) To resume execution from a specific point within the program
c) To skip the current iteration of a loop and continue with the next iteration
d) To raise a custom exception with a user-defined error message
Answer: c) To skip the current iteration of a loop and continue with the next iteration
1. In MySQL, what is the primary purpose of using exception handling in stored procedures and
functions?
a) To improve query performance
b) To define complex data types
c) To handle errors and unexpected situations gracefully
d) To manage user privileges and access control
Answer: c) To handle errors and unexpected situations gracefully
2. When defining an exception handler in MySQL, what statement is used to start the handler block?
a) BEGIN
b) EXCEPTION
c) HANDLER
d) DECLARE
Answer: c) HANDLER
3. In MySQL, what happens if an exception is raised in a stored procedure or function, and there is no
appropriate exception handler defined to catch it?
a) The program continues executing normally without any issues.
b) The program terminates with an error message and rolls back any changes made within the
procedure.
c) The database automatically creates a default handler to catch the exception.
d) The program waits indefinitely for an external handler to be defined.
Answer: b) The program terminates with an error message and rolls back any changes made within
the procedure.
4. When defining an exception handler in MySQL, what condition can be used to catch any unhandled
exception?
a) EXCEPTION
b) HANDLER NOT FOUND
c) SQLEXCEPTION
d) CONTINUE
Answer: c) SQLEXCEPTION
5. In MySQL, what action can be taken using an exception handler when a specific error condition
occurs in a stored procedure?
a) Resume execution from the point of exception occurrence
b) Raise another exception with a custom error message
c) Terminate the program immediately with an error message
d) Execute another stored procedure to handle the exception
Answer: a) Resume execution from the point of exception occurrence
6. In a MySQL exception handler, what is the purpose of using the RESIGNAL statement?
a) To rethrow the current exception to an outer exception handler
b) To raise a custom exception with a user-defined error code and message
c) To stop the execution of the stored procedure and terminate the program
d) To handle all uncaught exceptions within the procedure
Answer: a) To rethrow the current exception to an outer exception handler
7. What is the recommended approach for defining exception handlers in MySQL stored procedures
and functions?
a) Define a single generic exception handler to catch all possible errors.
b) Do not define any exception handlers to let the database handle exceptions automatically.
c) Define separate exception handlers for specific error conditions that need special treatment.
d) Use a single exception handler for all stored procedures and functions in the database.
Answer: c) Define separate exception handlers for specific error conditions that need special
treatment.
8. When defining an exception handler in MySQL, what condition can be used to catch warnings rather
than errors?
a) SQLERROR
b) SQLWARNING
c) SQLINFO
d) SQLEXCEPTION
Answer: b) SQLWARNING
9. In a MySQL stored procedure, how can you handle an exception that occurs during an SQL
statement execution?
a) Use a TRY-CATCH block to catch the exception and execute alternate statements.
b) Define a generic exception handler to catch all possible errors.
c) Rethrow the exception to an outer exception handler using the RESIGNAL statement.
d) Terminate the program and return an error message to the user.
Answer: c) Rethrow the exception to an outer exception handler using the RESIGNAL statement.
10. In MySQL, what happens if an exception is raised within a transaction and there is no handler to
catch it?
a) The transaction is automatically rolled back, and the program continues execution.
b) The transaction is committed, and the program terminates with an error message.
c) The transaction remains open indefinitely, waiting for a handler to be defined.
d) The database automatically creates a default handler to catch the exception.
Answer: b) The transaction is committed, and the program terminates with an error message.
Lecture 12: Introduction to NoSQL Databases and MongoDB
2. Which of the following statements best describes the main purpose of NoSQL databases?
a) To exclusively handle structured data with SQL queries
b) To provide a standardized data model for all types of databases
c) To handle large volumes of unstructured or semi-structured data
d) To replace traditional relational databases entirely
Answer: c) To handle large volumes of unstructured or semi-structured data
3. In the context of NoSQL databases, what is the primary focus in terms of data scalability?
a) Horizontal scalability
b) Vertical scalability
c) Sequential scalability
d) Concurrent scalability
Answer: a) Horizontal scalability
4. Which aspect of NoSQL databases allows them to be more flexible and adaptable to changing data
requirements?
a) Strict schema enforcement
b) ACID transactions
c) Dynamic data schema
d) Fixed data types
Answer: c) Dynamic data schema
6. Which type of data is typically best suited for storage and retrieval in a NoSQL database?
a) Highly normalized and structured data
b) Hierarchical data with complex relationships
c) Simple and structured tabular data
d) Unstructured or semi-structured data
Answer: d) Unstructured or semi-structured data
7. Which database model does NoSQL deviate from, allowing for more flexible data representation?
a) Hierarchical model
b) Network model
c) Relational model
d) Object-oriented model
Answer: c) Relational model
8. What is the primary advantage of using NoSQL databases for big data applications?
a) Strict data consistency and immediate data availability
b) Strong adherence to ACID properties for data transactions
c) High scalability and distributed architecture support
d) Support for complex SQL queries and joins
Answer: c) High scalability and distributed architecture support
9. Which aspect of NoSQL databases makes them suitable for applications with rapid data growth and
variable data structures?
a) Strong consistency model
b) Static and predefined schema
c) Strict data validation and enforcement
d) Schema flexibility and easy data schema evolution
Answer: d) Schema flexibility and easy data schema evolution
10. What type of NoSQL database is designed to provide the most efficient storage and retrieval of
key-value pairs?
a) Document store
b) Column-oriented store
c) Graph database
d) Key-value store
Answer: d) Key-value store
1. Which feature of NoSQL databases allows for flexible and schema-less data representation?
a) ACID transactions
b) Fixed data types
c) Dynamic data schema
d) Strong consistency model
Answer: c) Dynamic data schema
2. What does the term "eventual consistency" mean in the context of NoSQL databases?
a) The database will eventually reach a consistent state after a transaction.
b) Data consistency is guaranteed for all read and write operations.
c) Data consistency is always ensured immediately after each write operation.
d) The database may have temporary inconsistencies, but they will be resolved over time.
Answer: d) The database may have temporary inconsistencies, but they will be resolved over time.
3. Which feature of NoSQL databases allows for easy horizontal scaling across multiple nodes?
a) Fixed data schema
b) ACID transactions
c) BASE model
d) Horizontal partitioning
Answer: d) Horizontal partitioning
5. Which feature of NoSQL databases allows for easy and efficient storage of large volumes of
unstructured data?
a) Strong consistency model
b) Hierarchical data model
c) Column-oriented storage
d) Document-oriented storage
Answer: d) Document-oriented storage
6. What does the BASE acronym stand for in the context of NoSQL databases?
a) Basic, Atomic, Scalable, Eventually consistent
b) Balanced, Atomic, Strict, Eventual
c) Basic, Atomic, Strong, Eventually consistent
d) Balanced, Atomic, Scalable, Eventual
Answer: a) Basic, Atomic, Scalable, Eventually consistent
7. Which type of NoSQL database is best suited for applications that require high-performance retrieval
of data by key?
a) Column-oriented store
b) Graph database
c) Key-value store
d) Document store
Answer: c) Key-value store
8. What is the primary advantage of using the BASE model over the ACID model in NoSQL databases?
a) Strong data consistency at all times
b) Simplicity in data modeling and query language
c) Lower latency and higher availability of data
d) Compatibility with traditional relational databases
Answer: c) Lower latency and higher availability of data
9. Which feature of NoSQL databases allows for easy data distribution and replication across multiple
nodes?
a) Sharding
b) Fixed data schema
c) Strong consistency model
d) Hierarchical data model
Answer: a) Sharding
10. In NoSQL databases, which model prioritizes availability and partition tolerance over strict
consistency during network failures?
a) ACID model
b) BASE model
c) CAP theorem
d) RDBMS model
Answer: c) CAP theorem
1. What is the main characteristic that distinguishes structured data from semi-structured and
unstructured data?
a) Structured data has a fixed schema,
2. Which of the following data formats is commonly associated with structured data?
a) JSON
b) XML
c) CSV
d) Text documents
Answer: c) CSV
3. In the context of data, what does "schema-on-read" mean, particularly for semi-structured and
unstructured data?
a) The data is automatically transformed into a predefined schema during the read operation.
b) The data is read as-is without any schema transformation or validation.
c) The schema is dynamically generated during the write operation and enforced during reads.
d) The data is stored in multiple schemas, and the appropriate one is chosen during the read operation.
Answer: b) The data is read as-is without any schema transformation or validation.
4. Which type of data is most likely to be stored in a traditional relational database as structured data?
a) Images and multimedia files
b) Log files and system data
c) Employee records and sales transactions
d) Social media posts and web pages
Answer: c) Employee records and sales transactions
5. What is an example of semi-structured data format commonly used to represent hierarchical data?
a) CSV
b) JSON
c) Text documents
d) Relational tables
Answer: b) JSON
6. In the context of data storage, what is the main challenge of handling unstructured data?
a) Ensuring data consistency and integrity
b) Designing an appropriate schema for the data
c) Choosing the right data format for storage
d) Efficiently querying and indexing the data
Answer: b) Designing an appropriate schema for the data
8. Which data type is most suitable for representing a multimedia file such as an image or video?
a) Structured data
b) Semi-structured data
c) Unstructured data
d) Hierarchical data
Answer: c) Unstructured data
9. In a NoSQL database, which type of data is most commonly represented using JSON or BSON
formats?
a) Structured data
b) Semi-structured data
c) Unstructured data
d) Hierarchical data
Answer: b) Semi-structured data
10. Which data type is characterized by its fixed schema and organized into tables with rows and
columns?
a) Structured data
b) Semi-structured data
c) Unstructured data
d) Hierarchical data
Answer: a) Structured data
1. What is the main difference between traditional RDBMS and NoSQL databases in terms of data
modeling?
a) RDBMS uses a dynamic data schema, while NoSQL databases use a fixed schema.
b) RDBMS enforces strict data consistency, while NoSQL databases prioritize availability and
partition tolerance.
c) RDBMS is designed for unstructured data, while NoSQL databases are designed for structured
data.
d) RDBMS represents data in tabular form with fixed columns, while NoSQL databases use flexible
data formats like JSON.
Answer: d) RDBMS represents data in tabular form with fixed columns, while NoSQL databases use
flexible data formats like JSON.
3. In terms of scalability, what is a key advantage of NoSQL databases over traditional RDBMS?
a) RDBMS can scale horizontally across multiple nodes, while NoSQL databases cannot.
b) RDBMS can automatically handle sharding, while NoSQL databases require manual configuration.
c) NoSQL databases can easily scale horizontally across multiple nodes, while RDBMS has
limitations in this area.
d) NoSQL databases can only scale vertically, while RDBMS can scale both horizontally and
vertically.
Answer: c) NoSQL databases can easily scale horizontally across multiple nodes, while RDBMS has
limitations in this area.
4. Which type of databases is better suited for handling complex relationships between data entities?
a) RDBMS with structured tables and foreign key constraints
b) NoSQL databases with flexible data schemas and sharding capabilities
c) Both RDBMS and NoSQL databases are equally capable of handling complex relationships.
d) RDBMS with unstructured data storage capabilities
Answer: a) RDBMS with structured tables and foreign key constraints
6. In terms of data querying, what is the key difference between RDBMS and NoSQL databases?
a) RDBMS uses a flexible query language like MongoDB's query language.
b) NoSQL databases use SQL for querying data, just like RDBMS.
c) RDBMS uses SQL for querying data, while NoSQL databases have their own query languages
specific to their data model.
d) Both RDBMS and NoSQL databases use the same query language for data retrieval.
Answer: c) RDBMS uses SQL for querying data, while NoSQL databases have their own query
languages specific to their data model.
7. Which of the following is an advantage of RDBMS over NoSQL databases when it comes to data
consistency?
a) RDBMS guarantees immediate consistency for all data operations.
b) RDBMS can automatically handle sharding for horizontal scaling.
c) RDBMS has better support for unstructured data storage.
d) RDBMS allows for more flexible data schema evolution.
Answer: a) RDBMS guarantees immediate consistency for all data operations.
10. What is a common characteristic of RDBMS that makes it a preferred choice for applications
requiring strict data consistency and integrity?
a) Horizontal scalability across multiple nodes
b) Eventual consistency model
c) ACID transactions
d) BASE model
Answer: c) ACID transactions
1. According to the CAP theorem, a distributed database system can prioritize at most how many out of
the three properties: Consistency, Availability, and Partition Tolerance?
a) One
b) Two
c) Three
d) None
Answer: b) Two
7. What is the primary advantage of using the BASE model over the ACID model in distributed
databases?
a) Strong consistency at all times
b) Immediate data availability without any downtime
c) Lower latency and higher availability of data
d) Compatibility with traditional relational databases
Answer: c) Lower latency and higher availability of data
8. In the CAP theorem, if a distributed database prioritizes Consistency and Partition Tolerance, what
happens to Availability during network partitions?
a) Availability is guaranteed even during network partitions.
b) Availability may be compromised during network partitions.
c) Availability becomes irrelevant in this scenario.
d) Availability becomes unpredictable and may vary during network partitions.
Answer: b) Availability may be compromised during network partitions.
10. In the context of the CAP theorem, which property is most crucial for distributed databases that
need to handle network partitions?
a) Consistency
b) Availability
c) Partition Tolerance
d) Eventual consistency
Answer: c) Partition Tolerance
6. What is the primary benefit of using a column-oriented NoSQL database for certain types of queries?
a) Fast and efficient storage and retrieval of simple key-value pairs
b) Ability to handle complex data relationships and graph-based queries
c) Efficient storage and retrieval of large datasets with aggregated data
d) Support for dynamic data schema and easy data evolution
Answer: c) Efficient storage and retrieval of large datasets with aggregated data
9. Which type of NoSQL database is most suitable for representing highly connected and related data,
such as social networks or recommendation systems?
a) Key-value store
b) Document store
c) Column-oriented database
d) Graph database
Answer: d) Graph database
10. What type of data is best suited for storage in a key-value store NoSQL database?
a) Hierarchical data with complex relationships
b) Highly structured and tabular data
c) Simple data with a unique key identifier
d) Unstructured text and multimedia data
Answer: c) Simple data with a unique key identifier
1. MongoDB is a NoSQL database that falls under which category of NoSQL databases?
a) Key-value store
b) Document store
c) Column-oriented database
d) Graph database
Answer: b) Document store
4. What is the primary advantage of using MongoDB over traditional relational databases?
a) Strong data consistency at all times
b) Support for complex SQL queries and joins
c) Automatic sharding for horizontal scalability
d) Flexible schema and easy data representation with JSON documents
Answer: d) Flexible schema and easy data representation with JSON documents
10. What is the primary use case for MongoDB in real-world applications?
a) Storing complex graph data with many interconnected nodes.
b) Analyzing large datasets and performing complex data aggregation.
c) Web applications with high read and write throughput and flexible data models.
d) Storing simple key-value pairs for efficient data retrieval.
Answer: c) Web applications with high read and write throughput and flexible data models.
4. Which feature of MongoDB allows for automatic data distribution and load balancing across
multiple nodes?
a) Sharding
b) Indexing
c) Replication
d) Aggregation
Answer: a) Sharding
8. Which feature of MongoDB allows for performing complex data aggregation operations, such as
grouping and computing averages?
a) Indexing
b) Replication
c) Sharding
d) Aggregation Framework
Answer: d) Aggregation Framework
10. What is the role of the secondary nodes in a MongoDB replica set?
a) To store data for high availability and fault tolerance, but not handle write operations.
b) To act as the primary node for all write operations in case of primary node failure.
c) To handle read operations, but not write operations, to distribute the load from the primary node.
d) To automatically handle data sharding and horizontal scaling across multiple nodes.
Answer: a) To store data for high availability and fault tolerance, but not handle write operations.
: d) db.collection.deleteOne()
9. What is the primary benefit of using MongoDB Compass for database administration?
a) It provides a command-line interface for faster and more efficient database operations.
b) It allows for direct interaction with MongoDB databases through SQL queries.
c) It offers a visual and user-friendly interface for database management and data exploration.
d) It automatically handles sharding and horizontal scaling for large-scale databases.
Answer: c) It offers a visual and user-friendly interface for database management and data
exploration.
10. Which MongoDB command is used to perform a query and retrieve multiple documents from a
collection?
a) db.collection.find()
b) db.collection.query()
c) db.collection.retrieve()
d) db.collection.select()
Answer: a) db.collection.find()
Lecture 13: MongoDB Documents and Collections
**13.1 RDBMS & MongoDB Analogies: Relations/Tables => Collections; Tuples/Records =>
Documents**
2. What term is used in MongoDB to refer to individual data entries, similar to rows in a relational
database?
a) Tables
b) Rows
c) Collections
d) Documents
Answer: d) Documents
6. Which analogy correctly represents the relationship between a relational database and MongoDB's
document-based storage?
a) Database => Table; Collection => Row; Document => Column
b) Database => Collection; Collection => Table; Document => Row
c) Database => Collection; Collection => Row; Document => Column
d) Database => Table; Collection => Column; Document => Row
Answer: b) Database => Collection; Collection => Table; Document => Row
8. What term is used in MongoDB to refer to a specific data attribute within a document?
a) Rows
b) Tables
c) Fields
d) Collections
Answer: c) Fields
10. What is the key characteristic of MongoDB's document-based storage that makes it different from
traditional relational databases?
a) Support for complex joins and foreign key constraints
b) Ability to handle structured data with fixed schemas
c) Storage of related data in separate tables
d) Flexible schema and nested data structures
Answer: d) Flexible schema and nested data structures
3. What is the primary advantage of using JSON for data representation in MongoDB?
a) It is a binary format that reduces storage size.
b) It enforces strict data validation and schema constraints.
c) It allows for efficient indexing and querying of data.
d) It provides a flexible and human-readable data format.
Answer: d) It provides a flexible and human-readable data format.
6. Why is BSON preferred over JSON for internal data storage within MongoDB?
a) BSON is faster to process and query than JSON.
b) BSON is easier to write and read than JSON.
c) BSON provides better support for complex data structures and data types.
d) BSON is more secure and resistant to data corruption.
Answer: c) BSON provides better support for complex data structures and data types.
7. Which data format is generally used for data transmission and interchange with external systems in
MongoDB?
a) CSV
b) JSON
c) BSON
d) XML
Answer: b) JSON
8. In MongoDB, what is the key advantage of using BSON over JSON for storage and data
transmission?
a) BSON provides a more compact representation of data, reducing storage requirements.
b) BSON allows for faster query processing due to its binary format.
c) BSON enforces strict schema validation for data consistency.
d) BSON provides support for additional data types not available in JSON.
Answer: a) BSON provides a more compact representation of data, reducing storage requirements.
10. Which format is considered more efficient for data storage in MongoDB: JSON or BSON?
a) JSON, because it provides better readability and compatibility with other systems.
b) BSON, because it supports more data types and reduces storage size.
c) Both JSON and BSON have the same storage efficiency in MongoDB.
d) It depends on the use case and specific requirements of the application.
Answer: b) BSON, because it supports more data types and reduces storage size.
2. Which CRUD operation is used to insert new data into a MongoDB collection?
a) CREATE
b) READ
c) UPDATE
d) DELETE
Answer: a) CREATE
3. What is the primary method in MongoDB for creating new documents in a collection?
a) db.collection.insertOne()
b) db.collection.createDocument()
c) db.collection.createOne()
d) db.collection.newDocument()
Answer: a) db.collection.insertOne()
8. In MongoDB, how are updates specified when using the updateOne() method?
a) As a new document to replace the existing document
b) As a JSON-like object with the updated fields and values
c) As a SQL-like query statement with SET and WHERE clauses
d) As a binary BSON document for efficient data transfer
Answer: b) As a JSON-like object with the updated fields and values
10. What is the primary method for deleting data from a MongoDB collection?
a) db.collection.removeOne()
b) db.collection.erase()
c) db.collection.deleteOne()
d) db.collection.drop()
Answer: c) db.collection.deleteOne()
**13.4 UPSERT**
1. What does UPSERT stand for in the context of MongoDB and databases?
a) Upgrading and Sorting
b) Update and Select
c) Update or Insert
d) Upside and Downside
Answer: c) Update or Insert
2. In MongoDB, what does the UPSERT operation do?
a) It updates an existing document if it exists or inserts a new document if it does not exist.
b) It performs an update and a select operation simultaneously.
c) It retrieves data from one collection and inserts it into another collection.
d) It creates an index for faster data retrieval.
Answer: a) It updates an existing document if it exists or inserts a new document if it does not exist.
4. When using the updateOne() method with UPSERT, what happens if the document being updated is
not found?
a) An error is thrown, and the operation fails.
b) The method inserts a new document with the specified update criteria.
c) The method returns a warning message, but the operation continues.
d) The method updates all documents in the collection to match the update criteria.
Answer: b) The method inserts a new document with the specified update criteria.
7. When using the updateOne() method with UPSERT, can multiple documents be inserted if no
matching document is found?
a) Yes, the method can insert multiple documents.
b) No, the method only inserts a single document.
c) It depends on the available system resources.
d) It depends on the value of the "multi" option provided in the method call.
Answer: b) No, the method only inserts a single document.
8. Which option should be set to enable UPSERT behavior when using the updateOne() method?
a) set
b) update
c) insert
d) upsert
Answer: d) upsert
9. In UPSERT, if an insert operation is performed, does the new document automatically get an
ObjectID?
a) Yes, all documents in a collection have an ObjectID by default.
b) No, the new document must explicitly specify an ObjectID field.
c) It depends on the MongoDB configuration.
d) It depends on the availability of system resources during the operation.
Answer: a) Yes, all documents in a collection have an ObjectID by default.
10. What happens if the update criteria in UPSERT does not match any existing document or index in
the collection?
a) The update operation fails, and an error is thrown.
b) The method inserts a new document with the specified update criteria.
c) The method updates all documents in the collection to match the update criteria.
d) The method returns a warning message, but no action is taken.
Answer: b) The method inserts a new document with the specified update criteria.
Lecture 14: MongoDB Operators, Sorting, and Indexing
1. Which MongoDB operator is used to match documents where a specified field is equal to a certain
value?
a) $eq
b) $ne
c) $in
d) $exists
Answer: a) $eq
3. Which MongoDB operator is used to match documents where a specified field exists?
a) $eq
b) $ne
c) $in
d) $exists
Answer: d) $exists
5. Which MongoDB operator is used to combine multiple conditions with an AND logical operation?
a) $and
b) $or
c) $not
d) $nor
Answer: a) $and
7. Which MongoDB operator is used to perform a logical NOT operation on a specified condition?
a) $and
b) $or
c) $not
d) $nor
Answer: c) $not
**14.2 Sorting**
4. What is the MongoDB query to sort documents by a field named "age" in ascending order?
a) db.collection.find().sort("age": 1)
b) db.collection.find().sort({"age": -1})
c) db.collection.find().sort({"age": asc})
d) db.collection.find().sort("age": "asc")
Answer: a) db.collection.find().sort("age": 1)
8. How does sorting affect the original order of documents in a collection in MongoDB?
a) Sorting changes the order of documents permanently in the collection.
b) Sorting changes the order of documents temporarily for the current query only.
c) Sorting has no effect on the order of documents in the collection.
d) Sorting randomizes the order of documents in the collection.
Answer: b) Sorting changes the order of documents temporarily for the current query only.
10. Can you sort documents in MongoDB based on computed values or expressions?
a) Yes, using the sort() method with JavaScript functions.
b) No, sorting is only possible based on the existing field values.
c) Yes, by defining custom sorting algorithms in the MongoDB configuration.
d) No, MongoDB does not support sorting based on computed values.
Answer: b) No, sorting is only possible based on the existing field values.
**14.3 Indexing**
4. In MongoDB, how does indexing affect write operations (e.g., insert, update, delete)?
a) Indexing slows down write operations but improves read operations.
b) Indexing has no impact on write operations.
c) Indexing speeds up write operations but may slow down read operations.
d) Indexing ensures data consistency and prevents write operations from occurring.
Answer: c) Indexing speeds up write operations but may slow down read operations.
5. What is the primary benefit of using an index in a MongoDB collection?
a) It enforces data validation rules and constraints.
b) It reduces the storage size of the collection.
c) It prevents duplicate documents from being inserted.
d) It accelerates data retrieval for queries on indexed fields.
Answer: d) It accelerates data retrieval for queries on indexed fields.
9. In MongoDB, can you create an index on a nested field or a field within an embedded document?
a) No, MongoDB only supports indexing on top-level fields.
b) Yes, MongoDB allows indexing on nested fields to improve query performance.
c) Yes, but only if the nested field is of type "string" or "numeric."
d) It depends on the MongoDB version being used.
Answer: b) Yes, MongoDB allows indexing on nested fields to improve query performance.
7. Which of the following statements is true regarding Big Data and traditional data processing?
a) Big Data processing requires more time and resources than traditional data processing.
b) Traditional data processing is better suited for handling large volumes of data.
c) Big Data processing is limited to structured data only.
d) Big Data processing does not involve real-time analysis.
Answer: a) Big Data processing requires more time and resources than traditional data processing.
8. What is one of the key drivers behind the growth of Big Data?
a) The decline in data sources and sensors
b) The reduced need for data storage solutions
c) The increase in internet usage and connected devices
d) The lack of interest in data-driven decision making
Answer: c) The increase in internet usage and connected devices
9. How does Big Data differ from traditional data processing in terms of data sources?
a) Big Data relies on structured data from well-defined sources, while traditional data processing
handles diverse data from various sources.
b) Big Data and traditional data processing both rely solely on internal data sources within
organizations.
c) Big Data involves processing data from a single source, while traditional data processing deals
with data from multiple sources.
d) Big Data does not rely on data sources; it generates data on its own through AI algorithms.
Answer: a) Big Data relies on structured data from well-defined sources, while traditional data
processing handles diverse data from various sources.
10. What is the main purpose of using distributed systems in Big Data processing?
a) To increase the complexity of data analysis
b) To reduce the need for data storage
c) To enable parallel processing and handle large volumes of data
d) To limit the data variety in the analysis process
Answer: c) To enable parallel processing and handle large volumes of data
1. Which characteristic of Big Data refers to the sheer volume of data generated and collected?
a) Velocity
b) Variety
c) Volume
d) Veracity
Answer: c) Volume
2. Which of the following is an example of Big Data in the context of the Velocity characteristic?
a) A large collection of structured data in a relational database
b) Real-time social media streams generating massive amounts of unstructured data
c) A diverse dataset containing information from multiple sources
d) Data with high accuracy and reliability
Answer: b) Real-time social media streams generating massive amounts of unstructured data
4. Which of the following is an example of Big Data in the context of the Variety characteristic?
a) Sensor data from a single device
b) Customer information stored in a traditional relational database
c) Log files containing text data
d) A small collection of numerical data
Answer: c) Log files containing text data
6. An example of Big Data in the context of the Veracity characteristic would be:
a) A large collection of sensor data from a single device.
b) A dataset containing information from multiple sources with varying degrees of accuracy.
c) Real-time social media streams generating massive amounts of unstructured data.
d) A small collection of numerical data from a controlled environment.
Answer: b) A dataset containing information from multiple sources with varying degrees of accuracy.
7. Which characteristic of Big Data is associated with the speed at which data is generated and
collected?
a) Velocity
b) Variety
c) Volume
d) Veracity
Answer: a) Velocity
8. An example of Big Data in the context of the Volume characteristic would be:
a) A diverse dataset containing information from multiple sources.
b) A large collection of sensor data from a single device.
c) Real-time social media streams generating massive amounts of unstructured data.
d) A small collection of numerical data from a controlled environment.
Answer: b) A large collection of sensor data from a single device.
9. Which characteristic of Big Data is associated with the diversity of data types and formats?
a) Velocity
b) Variety
c) Volume
d) Veracity
Answer: b) Variety
10. An example of Big Data in the context of the Velocity characteristic would be:
a) A dataset containing information from multiple sources with varying degrees of accuracy.
b) A diverse dataset containing information from multiple sources.
c) A large collection of sensor data from a single device.
d) A small collection of numerical data from a controlled environment.
Answer: c) A large collection of sensor data from a single device.
1. Which property of Big Data refers to the ability to process and analyze data in real-time or near-real-
time?
a) Scalability
b) Velocity
c) Variety
d) Latency
Answer: b) Velocity
2. What does the property of "Scalability" mean in the context of Big Data?
a) The ability to handle increasing amounts of data with ease.
b) The ability to process data with high accuracy and reliability.
c) The ability to store data in a variety of formats.
d) The ability to process data in real-time.
Answer: a) The ability to handle increasing amounts of data with ease.
3. Which property of Big Data is associated with the accuracy and reliability of the data?
a) Scalability
b) Velocity
c) Variety
d) Veracity
Answer: d) Veracity
5. Which property of Big Data is associated with the diversity of data types and sources?
a) Scalability
b) Velocity
c) Variety
d) Veracity
Answer: c) Variety
7. Which property of Big Data is associated with the ability to process data in real-time or near-real-
time?
a) Scalability
b) Velocity
c) Variety
d) Latency
Answer: b) Velocity
2. Which component of a Big Data system is responsible for storing and managing large volumes of
data?
a) Data Source
b) Data Processor
c) Data Storage
d) Data Visualization
Answer: c) Data Storage
4. Which component of a Big Data system is responsible for presenting the data in a meaningful and
understandable way?
a) Data Source
b) Data Processor
c) Data Storage
d) Data Visualization
Answer: d) Data Visualization
6. Which component of a Big Data system is responsible for ensuring data security and privacy?
a) Data Source
b) Data Processor
c) Data Storage
d) Data Security
Answer: d) Data Security
7. What does the Data Visualization component in a Big Data system provide?
a) Data storage and management functionalities.
b) Real-time data processing and analysis capabilities.
c) Tools and techniques to process and analyze the raw data.
d) Graphs, charts, and dashboards to present the data in a visual format.
Answer: d) Graphs, charts, and dashboards to present the data in a visual format.
8. Which component of a Big Data system is responsible for ensuring data consistency and integrity?
a) Data Source
b) Data Processor
c) Data Storage
d) Data Governance
Answer: d) Data Governance