














































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































































Question 1. Which component of MySQL architecture is responsible for handling SQL parsing, optimization, and execution? A) Storage Engine B) Client Library C) Query Processor D) Replication Thread Answer: C Explanation: The Query Processor (also called the SQL layer) parses, optimizes, and executes statements, while storage engines handle data storage. Question 2. In MySQL, the Data Dictionary stores metadata about which of the following? A) User passwords only B) Table definitions, columns, indexes, and privileges C) Binary log events D) Temporary files on disk Answer: B Explanation: The Data Dictionary contains metadata such as schemas, tables, columns, indexes, constraints, and user privileges. Question 3. Which MySQL distribution includes the Enterprise Monitor, Enterprise Backup, and a commercial support agreement? A) MySQL Community Server B) MariaDB Server C) MySQL Enterprise Edition D) Percona Server Answer: C
Explanation: MySQL Enterprise Edition provides proprietary tools and commercial support not found in the free Community edition. Question 4. On a Linux system, which command safely stops the MySQL server? A) service mysql restart B) mysqladmin shutdown C) systemctl start mysqld D) mysqld_safe --stop Answer: B Explanation: mysqladmin shutdown sends a shutdown command to the server, ensuring a graceful stop. Question 5. Which configuration file is read first by the MySQL server on Unix-like systems? A) my.cnf in the current directory B) /etc/my.cnf C) /usr/local/mysql/etc/my.cnf D) /etc/mysql/my.cnf Answer: D Explanation: The server reads /etc/mysql/my.cnf first, then other locations; the order is defined by the MySQL option file hierarchy. Question 6. Setting sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_DATE' accomplishes what? A) Enables case‑sensitive table names B) Forces strict error handling for transactional tables and disallows '0000‑ 00 ‑00' dates C) Allows automatic creation of indexes on foreign keys D) Disables binary logging
D) SET ENGINE = InnoDB ON t; Answer: A Explanation: ALTER TABLE … ENGINE = InnoDB; converts the table’s storage engine. Question 10. In an ER diagram, a diamond shape typically represents which concept? A) Entity B) Attribute C) Relationship D) Primary key Answer: C Explanation: Diamonds denote relationships between entities in ER modeling. Question 11. Which normal form eliminates partial dependencies on a composite primary key? A) 1NF B) 2NF C) 3NF D) BCNF Answer: B Explanation: 2NF removes partial dependencies where a non‑key attribute depends on part of a composite key. Question 12. In a many‑to‑many relationship, which database object is required to implement the relationship? A) Composite primary key in one table B) A junction (association) table with foreign keys to both sides C) A unique index on each table
D) A CHECK constraint on both tables Answer: B Explanation: A junction table stores pairs of foreign keys, representing the many‑to‑many links. Question 13. Which MySQL data type is best suited for storing fixed‑length, case‑sensitive strings of exactly 10 characters? A) VARCHAR(10) B) CHAR(10) BINARY C) TEXT D) VARBINARY(10) Answer: B Explanation: CHAR(10) BINARY stores exactly 10 bytes and is case‑sensitive. Question 14. When would you choose the DECIMAL data type over FLOAT? A) For storing large integers B) When exact precision for monetary values is required C) For storing scientific measurements with high range D) When you need automatic rounding Answer: B Explanation: DECIMAL stores exact fixed‑point numbers, avoiding the rounding errors inherent in floating‑point types. Question 15. Which temporal type automatically updates to the current timestamp when a row is modified? A) DATE B) DATETIME C) TIMESTAMP with ON UPDATE CURRENT_TIMESTAMP
Answer: C Explanation: The UNIQUE constraint enforces distinct values, while PRIMARY KEY also implies uniqueness but also NOT NULL. Question 19. How does the AUTO_INCREMENT attribute determine the next value for a new row? A) Randomly generated by the server B) The maximum existing value plus one, unless a higher value is set in the AUTO_INCREMENT option C) Always starts at zero for each insert D) It cycles back to 1 after reaching the maximum Answer: B Explanation: MySQL stores the current auto‑increment counter; it increments from the highest existing value or the explicit AUTO_INCREMENT = n setting. Question 20. Which statement correctly adds a NOT NULL constraint to an existing column email in table users? A) ALTER TABLE users MODIFY email VARCHAR(255) NOT NULL; B) ALTER TABLE users ADD CONSTRAINT NOT NULL (email); C) UPDATE users SET email = '' WHERE email IS NULL; D) ALTER TABLE users CHANGE email email NOT NULL; Answer: A Explanation: MODIFY changes column definition, allowing addition of NOT NULL.
Question 21. Which SELECT clause is used to retrieve only distinct rows from a query? A) UNIQUE B) DISTINCT C) GROUP BY ALL D) HAVING DISTINCT Answer: B Explanation: SELECT DISTINCT eliminates duplicate rows in the result set. Question 22. To insert multiple rows in a single statement, which syntax is correct? A) INSERT INTO t VALUES (1, 'a'), (2, 'b'); B) INSERT MULTIPLE INTO t (id, name) VALUES (1, 'a'), (2, 'b'); C) INSERT ALL INTO t VALUES (1, 'a'); INSERT ALL INTO t VALUES (2, 'b'); D) INSERT INTO t SELECT * FROM other; Answer: A Explanation: MySQL allows a comma‑separated list of row value expressions after VALUES. Question 23. Which clause updates only the rows where status is NULL? A) UPDATE orders SET status='new' WHERE status IS NULL; B) UPDATE orders SET status='new' IF status = NULL; C) UPDATE orders SET status='new' WHERE status = NULL; D) UPDATE orders SET status='new' HAVING status IS NULL; Answer: A Explanation: IS NULL is the proper test for NULL values; = cannot be used. Question 24. Which statement removes all rows from logs but keeps the table structure and its indexes?
Answer: B Explanation: HAVING applies conditions to the result of GROUP BY aggregates, whereas WHERE filters rows before grouping. Question 28. Which clause limits the result set to the first 10 rows after sorting? A) LIMIT 10 OFFSET 0 B) TOP 10 C) FETCH FIRST 10 ROWS ONLY D) ROWS 1- 10 Answer: A Explanation: MySQL uses LIMIT (optionally with OFFSET) to restrict rows returned. Question 29. Which join type returns all rows from the left table and matching rows from the right table, but includes left rows with no match? A) INNER JOIN B) LEFT OUTER JOIN C) RIGHT OUTER JOIN D) CROSS JOIN Answer: B Explanation: LEFT OUTER JOIN (or simply LEFT JOIN) keeps all left‑table rows, inserting NULLs for missing right‑table rows. Question 30. To find rows in employees that have no matching entry in departments, which query is appropriate?
A) SELECT * FROM employees LEFT JOIN departments ON employees.dept_id = departments.id WHERE departments.id IS NULL; B) SELECT * FROM employees RIGHT JOIN departments ON employees.dept_id = departments.id WHERE employees.id IS NULL; C) SELECT * FROM employees INNER JOIN departments ON employees.dept_id = departments.id; D) SELECT * FROM employees WHERE NOT EXISTS (SELECT 1 FROM departments WHERE departments.id = employees.dept_id); Answer: A Explanation: A left join with a WHERE … IS NULL on the right‑table column identifies unmatched rows. Question 31. Which statement combines the result sets of two SELECT queries and removes duplicate rows? A) UNION ALL B) UNION C) INTERSECT D) CONCAT Answer: B Explanation: UNION merges results and eliminates duplicates; UNION ALL keeps all rows. Question 32. Which operator is used for pattern matching that supports regular expressions? A) LIKE B) REGEXP C) MATCH D) PATTERN Answer: B
Question 36. Which CASE expression returns 'Adult' when age >= 18, otherwise 'Minor'? A) CASE WHEN age >= 18 THEN 'Adult' ELSE 'Minor' END B) IF(age >= 18, 'Adult', 'Minor') C) SELECT IF(age >= 18, 'Adult', 'Minor') D) ALL OF THE ABOVE Answer: D Explanation: Both the CASE syntax (A) and the IF() function (B) achieve the same conditional output. Question 37. Which statement creates a view named v_active_users that selects only users with status='active'? A) CREATE VIEW v_active_users AS SELECT * FROM users WHERE status='active'; B) CREATE VIEW v_active_users SELECT * FROM users WHERE status='active'; C) ALTER VIEW v_active_users AS SELECT * FROM users WHERE status='active'; D) DEFINE VIEW v_active_users AS SELECT * FROM users WHERE status='active'; Answer: A Explanation: CREATE VIEW view_name AS SELECT … defines a view. Question 38. Which of the following views is updatable? A) A view that joins two tables B) A view that contains an aggregate function (e.g., SUM) C) A view that selects from a single table without GROUP BY, DISTINCT, or subqueries D) A view that uses UNION Answer: C Explanation: Simple single‑table views without aggregation, DISTINCT, or joins are updatable. Question 39. What is a primary advantage of using a view for security?
A) Views encrypt the underlying data automatically B) Views can hide columns or rows from users without granting them direct table access C) Views improve query performance dramatically D) Views replace the need for user accounts Answer: B Explanation: By granting SELECT on a view, you expose only the columns/rows you want the user to see. Question 40. Which statement correctly creates a stored procedure named sp_add_product that inserts a row into products? A) CREATE PROCEDURE sp_add_product (IN p_name VARCHAR(50)) INSERT INTO products(name) VALUES (p_name); B) CREATE PROCEDURE sp_add_product (IN p_name VARCHAR(50)) BEGIN INSERT INTO products(name) VALUES (p_name); END; C) CREATE FUNCTION sp_add_product (p_name VARCHAR(50)) RETURNS INT BEGIN INSERT … END; D) CREATE PROC sp_add_product AS INSERT INTO …; Answer: B Explanation: Stored procedures use CREATE PROCEDURE … BEGIN … END; and can accept parameters. Question 41. In a stored function, which keyword must be used to return a value? A) RETURN B) OUTPUT C) YIELD D) GOTO Answer: A Explanation: RETURN expression; sends the result back to the caller.
A) They can modify data in other tables B) They cannot contain COMMIT or ROLLBACK statements C) They can be defined for multiple events simultaneously D) They can be called directly with CALL syntax Answer: B Explanation: Triggers run within the surrounding transaction and cannot issue explicit COMMIT/ROLLBACK. Question 46. Which window function assigns a unique sequential integer to rows ordered by salary descending? A) ROW_NUMBER() OVER (ORDER BY salary DESC) B) RANK() OVER (ORDER BY salary DESC) C) DENSE_RANK() OVER (ORDER BY salary DESC) D) NTILE(10) OVER (ORDER BY salary DESC) Answer: A Explanation: ROW_NUMBER() provides a distinct sequence without gaps; RANK may produce gaps. Question 47. A Common Table Expression (CTE) is defined using which clause? A) WITH B) START WITH C) CTE AS D) SELECT CTE Answer: A Explanation: WITH cte_name AS (SELECT …) SELECT … FROM cte_name; defines a CTE. Question 48. Which privilege allows a user to create new databases?
D) All of the above (they are synonyms) Answer: D Explanation: In MySQL CREATE, CREATE DATABASE, and CREATE SCHEMA grant the same ability. Question 49. To grant SELECT permission on all tables in the sales database to user bob@%, which command is correct? A) GRANT SELECT ON sales.* TO 'bob'@'%'; B) GRANT SELECT ON . TO 'bob'@'%'; C) GRANT ALL ON sales.* TO 'bob'@'%'; D) SET PRIVILEGES SELECT ON sales TO 'bob'@'%'; Answer: A Explanation: sales.* specifies all tables in the sales database. Question 50. Which statement revokes the INSERT privilege from user alice on table orders? A) REVOKE INSERT ON orders FROM 'alice'@'localhost'; B) DROP PRIVILEGE INSERT ON orders FROM 'alice'@'localhost'; C) REVOKE ALL ON orders FROM 'alice'@'localhost'; D) REMOVE INSERT FROM 'alice'@'localhost'; Answer: A Explanation: REVOKE removes specific privileges. Question 51. What does the ROLE statement CREATE ROLE analyst; accomplish?
B) MySQL Enterprise Audit C) MySQL Enterprise Monitor D) MySQL Enterprise Backup Answer: C Explanation: Enterprise Monitor offers performance dashboards and query analysis. Question 55. Which index type is optimized for full‑text search on large text columns? A) B‑tree B) HASH C) FULLTEXT D) SPATIAL Answer: C Explanation: FULLTEXT indexes enable natural‑language search on CHAR, VARCHAR, or TEXT. Question 56. When should you create a composite index on columns (a, b) instead of separate single‑column indexes? A) When queries always filter on both a and b together, respecting the leftmost prefix rule B) When you need to enforce uniqueness on column b only C) When a and b are never used together in a WHERE clause D) When both columns are of type BLOB Answer: A Explanation: Composite indexes are useful when the query filters on the leading columns in order. Question 57. In InnoDB, the primary key is automatically a __________ index. A) Secondary
B) Full‑text C) Clustered D) Hash Answer: C Explanation: InnoDB clusters the table data around the primary key, making it a clustered index. Question 58. Which EXPLAIN output column shows the index MySQL actually used for a table? A) type B) key C) rows D) Extra Answer: B Explanation: The key column displays the name of the index chosen for the table. Question 59. If EXPLAIN shows type = ALL for a query, what does it indicate? A) The query uses a full table scan, which is usually inefficient B) The query uses an index merge C) The query uses a range scan D) The query uses a constant lookup Answer: A Explanation: type = ALL means a full scan of the table, often a sign to add an index. Question 60. Which rewrite eliminates a correlated subquery that slows down performance? A) Replace it with a JOIN that pre‑aggregates the needed data B) Add a LIMIT 1 to the subquery