
















































































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 MySQL storage engine provides ACID‑compliant transactions and row‑level locking? A) MyISAM B) MEMORY C) InnoDB D) CSV Answer: C Explanation: InnoDB is the default engine that supports transactions, foreign keys, and row‑level locking, fulfilling ACID properties. Question 2. What does the MySQL data type DATETIME(6) store? A) Date only, no time B) Time only, no date C) Date and time with microsecond precision D) Unix timestamp Answer: C Explanation: DATETIME(6) stores a date and time value including up to six digits of fractional seconds (microseconds). Question 3. Which constraint ensures that a column cannot contain NULL values? A) PRIMARY KEY B) UNIQUE C) NOT NULL D) CHECK Answer: C Explanation: The NOT NULL constraint disallows NULL entries for the defined column.
Question 4. Which of the following statements creates a view that is updatable? A) CREATE VIEW v_emp AS SELECT * FROM employee WHERE salary > 5000; B) CREATE VIEW v_emp AS SELECT emp_id, salary FROM employee GROUP BY salary; C) CREATE VIEW v_emp AS SELECT emp_id, COUNT(*) FROM employee GROUP BY emp_id; D) CREATE VIEW v_emp AS SELECT * FROM employee LIMIT 10; Answer: A Explanation: A view that selects from a single table without aggregation, DISTINCT, GROUP BY, or subqueries is updatable; option A meets those criteria. Question 5. Which clause would you use to retrieve only unique values from a column? A) GROUP BY B) HAVING C) DISTINCT D) UNIQUE Answer: C Explanation: The DISTINCT keyword eliminates duplicate rows in the result set. Question 6. In a SELECT statement, which operator is used to match a pattern that starts with “A” and ends with any three characters? A) LIKE 'A___' B) LIKE 'A%' C) LIKE '_A%' D) REGEXP '^A.{3}$' Answer: A Explanation: The underscore _ matches a single character; three underscores after A require exactly three trailing characters.
Explanation: LEFT JOIN (or LEFT OUTER JOIN) preserves all rows from the left side and fills with NULLs for non‑matching right‑side rows. Question 10. Which MySQL clause allows you to filter groups after aggregation? A) WHERE B) HAVING C) ORDER BY D) LIMIT Answer: B Explanation: HAVING is evaluated after GROUP BY and can filter based on aggregate functions. Question 11. What does the function DATE_ADD('2023- 01 - 01', INTERVAL 10 DAY) return? A) 2023‑ 01 ‑ 11 B) 2023‑ 01 ‑ 10 C) 2023‑ 01 ‑01 10:00: D) NULL Answer: A Explanation: DATE_ADD adds the specified interval (10 days) to the date, resulting in 2023 ‑ 01 ‑11. Question 12. Which MySQL scalar function extracts the year from a DATE value? A) YEAR() B) EXTRACT(YEAR FROM ...) C) DATE_FORMAT(...,'%Y') D) All of the above Answer: D
Explanation: All three syntaxes (YEAR(), EXTRACT(), and DATE_FORMAT()) can retrieve the year component. Question 13. What does the CASE WHEN salary > 5000 THEN 'High' ELSE 'Low' END expression evaluate to? A) A boolean value B) A numeric value C) A string value based on the condition D) NULL if salary is NULL Answer: C Explanation: The CASE expression returns the string 'High' or 'Low' depending on the salary condition. Question 14. Which window function assigns a unique sequential number to rows ordered by hire_date? A) ROW_NUMBER() OVER (ORDER BY hire_date) B) RANK() OVER (ORDER BY hire_date) C) DENSE_RANK() OVER (ORDER BY hire_date) D) NTILE(10) OVER (ORDER BY hire_date) Answer: A Explanation: ROW_NUMBER() generates a consecutive integer for each row in the defined order. Question 15. What is the result of SELECT 1 UNION SELECT 1;? A) Two rows with value 1 B) One row with value 1 C) Error – duplicate rows not allowed
D) CREATE PROCEDURE get_emp(p_id) SELECT * FROM emp; Answer: B Explanation: Parameters must be declared with a mode (IN, OUT, INOUT). Option B follows the correct syntax. Question 19. Which MySQL construct is used to handle a division‑by‑zero error inside a stored routine? A) DECLARE CONTINUE HANDLER FOR SQLEXCEPTION B) DECLARE EXIT HANDLER FOR DIVISION_BY_ZERO C) SIGNAL SQLSTATE '22012' D) Both A and B are valid ways Answer: D Explanation: Both a generic SQLEXCEPTION handler and a specific DIVISION_BY_ZERO handler can be declared; both are acceptable. Question 20. What is the purpose of a BEFORE INSERT trigger? A) To modify the row after it has been stored B) To validate or change column values before the row is inserted C) To delete rows automatically after insertion D) To log the insertion into a separate audit table only after commit Answer: B Explanation: A BEFORE INSERT trigger fires prior to the actual insertion, allowing validation or alteration of the incoming row data. Question 21. Which MySQL statement schedules a daily event at 02:00 AM to purge old logs? A) CREATE EVENT purge_logs ON SCHEDULE EVERY 1 DAY STARTS '2023- 01 - 01 02:00:00' DO DELETE FROM logs WHERE created_at < NOW() - INTERVAL 30 DAY;
B) CREATE EVENT purge_logs EVERY 1 DAY AT '02:00' DO ... C) SCHEDULE EVENT purge_logs EVERY DAY AT '02:00' DO ... D) EVENT CREATE purge_logs EVERY 1 DAY STARTS CURRENT_TIME + INTERVAL 2 HOUR DO ... Answer: A Explanation: The correct syntax uses CREATE EVENT … ON SCHEDULE EVERY 1 DAY STARTS 'yyyy-mm-dd hh:mm:ss'. Question 22. Which index type is optimized for full‑text search on large text columns? A) BTREE B) HASH C) FULLTEXT D) SPATIAL Answer: C Explanation: FULLTEXT indexes support natural language and boolean full‑text searches on CHAR, VARCHAR, or TEXT columns. Question 23. What does the EXPLAIN output column type = ALL indicate? A) The query uses a primary key lookup B) The optimizer will perform a full table scan C) The query uses a range scan on an indexed column D) The query uses a temporary table Answer: B Explanation: type = ALL means a full table scan, which is usually the least efficient access method. Question 24. Which MySQL configuration variable enables the slow query log? A) log_error
A) CREATE CHECK (info REGEXP '^\{.*\}$') B) ALTER TABLE t ADD CONSTRAINT chk_json CHECK (JSON_VALID(info)) C) SET sql_mode = 'STRICT_JSON' D) Use a BEFORE INSERT trigger to parse the string Answer: B Explanation: The JSON_VALID() function returns 1 for valid JSON; a CHECK constraint can enforce it. Question 28. Which MySQL X DevAPI method inserts a document into a collection? A) collection.add(doc).execute() B) collection.insertOne(doc) C) collection.save(doc) D) collection.push(doc) Answer: A Explanation: In X DevAPI, collection.add(document).execute() adds a document to a collection. Question 29. Which connector class in Java is used for MySQL connectivity? A) com.mysql.jdbc.Driver B) org.postgresql.Driver C) java.sql.MySQLConnector D) com.mysql.cj.jdbc.Driver Answer: D Explanation: The current MySQL Connector/J driver class is com.mysql.cj.jdbc.Driver. Question 30. Which MySQL SQL mode forces strict handling of invalid or out‑of‑range values? A) NO_ZERO_DATE
Answer: B Explanation: STRICT_TRANS_TABLES (or STRICT_ALL_TABLES) makes MySQL reject or adjust invalid data rather than silently truncating. Question 31. What does a prepared statement protect against? A) Deadlocks B) SQL injection attacks C) Duplicate key errors D) Slow queries Answer: B Explanation: By separating query structure from data, prepared statements prevent malicious input from being interpreted as code. Question 32. Which spatial index type does MySQL use for geometry columns? A) BTREE B) R‑TREE (implemented via SPATIAL index) C) HASH D) GIST Answer: B Explanation: MySQL implements spatial indexes as R‑Tree structures for geometry data types. Question 33. Which function returns the distance (in meters) between two POINT values? A) ST_Distance_Sphere(p1, p2) B) ST_Distance(p1, p2)
Question 36. What does the ON DELETE CASCADE clause do in a foreign key definition? A) Prevents deletion of parent rows if child rows exist B) Deletes child rows automatically when the parent row is deleted C) Sets child foreign key values to NULL on parent delete D) Raises an error on delete attempts Answer: B Explanation: ON DELETE CASCADE propagates the delete operation to dependent rows. Question 37. Which MySQL function returns the current session’s user and host? A) USER() B) CURRENT_USER() C) SESSION_USER() D) ALL OF THE ABOVE Answer: D Explanation: USER(), CURRENT_USER(), and SESSION_USER() all return the authenticated account; they differ slightly in privilege context but all are valid. Question 38. Which statement disables foreign key checks for the duration of a session? A) SET FOREIGN_KEY_CHECKS = 0; B) SET sql_mode = 'NO_FOREIGN_KEY_CHECKS'; C) ALTER SESSION SET FOREIGN_KEY_CHECKS = OFF; D) DISABLE FOREIGN KEY CHECKS; Answer: A Explanation: The system variable FOREIGN_KEY_CHECKS can be set to 0 to temporarily skip foreign‑key validation. Question 39. What is the result of SELECT CAST('2023- 02 - 30' AS DATE); in strict mode?
A) 2023‑ 02 ‑30 (invalid date is accepted) B) NULL with a warning C) 2023‑ 03 ‑02 (MySQL adjusts to a valid date) D) An error is raised and the statement fails Answer: D Explanation: In STRICT_TRANS_TABLES mode, casting an invalid date causes an error and aborts the statement. Question 40. Which MySQL keyword is used to rename a column without dropping the table? A) MODIFY COLUMN B) CHANGE COLUMN C) RENAME COLUMN D) ALTER COLUMN Answer: B Explanation: ALTER TABLE t CHANGE COLUMN old_name new_name datatype renames a column while optionally redefining its type. Question 41. Which MySQL function returns the number of rows affected by the most recent DML statement? A) ROW_COUNT() B) FOUND_ROWS() C) LAST_INSERT_ID() D) AFFECTED_ROWS() Answer: A Explanation: ROW_COUNT() reports how many rows were changed, inserted, or deleted by the last statement.
Explanation: Both SUBSTRING(str, n, 1) and MID(str, n) retrieve the character at position n. Question 45. Which MySQL optimizer hint forces the use of a specific index named idx_name? A) USE INDEX (idx_name) B) FORCE INDEX (idx_name) C) INDEX (idx_name) D) HINT INDEX idx_name Answer: B Explanation: FORCE INDEX (idx_name) tells the optimizer to use the given index even if it thinks another plan is better. Question 46. Which MySQL error code corresponds to a duplicate‑key violation? A) 1062 B) 1045 C) 1451 D) 2002 Answer: A Explanation: Error 1062 is “Duplicate entry … for key …”. Question 47. Which function can be used to generate a UUID value in MySQL? A) UUID() B) GUID() C) NEWID() D) RANDOM_UUID() Answer: A Explanation: UUID() returns a 36‑character universal unique identifier.
Question 48. What does the INFORMATION_SCHEMA.TABLES view provide? A) Row data from all tables B) Metadata about tables such as engine, row count, and creation time C) Execution plans for queries D) User privileges on tables Answer: B Explanation: INFORMATION_SCHEMA.TABLES contains metadata about each table in the database. Question 49. Which MySQL statement changes the current database without using USE? A) SET DATABASE = db_name; B) ALTER SESSION SET CURRENT_DATABASE = db_name; C) SELECT DATABASE(); D) None; USE db_name; is the only way Answer: D Explanation: The only command to change the default schema in a session is USE db_name;. Question 50. Which MySQL function returns the length of a string in bytes? A) CHAR_LENGTH() B) LENGTH() C) OCTET_LENGTH() D) Both B and C are synonyms Answer: D Explanation: LENGTH() and OCTET_LENGTH() both return the byte length; CHAR_LENGTH() returns character count.
Question 54. Which MySQL function returns the Unix timestamp (seconds since 1970‑ 01 ‑01) for a given DATETIME? A) UNIX_TIMESTAMP(datetime_expr) B) TO_UNIXTIME(datetime_expr) C) TIMESTAMPDIFF(SECOND, '1970- 01 - 01', datetime_expr) D) All of the above Answer: A Explanation: UNIX_TIMESTAMP() directly converts a datetime to a Unix epoch integer. Question 55. Which MySQL statement disables the binary log for the current session? A) SET sql_log_bin = 0; B) SET SESSION sql_log_bin = OFF; C) SET GLOBAL sql_log_bin = 0; D) LOGGING OFF; Answer: A Explanation: sql_log_bin is a session variable; setting it to 0 disables binary logging for that connection. Question 56. Which MySQL function can be used to round a number to the nearest integer? A) ROUND(num) B) CEIL(num) C) FLOOR(num) D) TRUNCATE(num) Answer: A
Explanation: ROUND() rounds to the nearest integer (or to a specified number of decimal places). Question 57. Which clause can be used to add a comment to a column definition? A) COMMENT 'text' B) NOTE 'text' C) DESCRIPTION 'text' D) COMMENTARY 'text' Answer: A Explanation: COMMENT 'text' adds a descriptive comment to a column or table. Question 58. Which MySQL statement returns the server version string? A) SELECT VERSION(); B) SHOW VARIABLES LIKE 'version'; C) SELECT @@version; D) All of the above Answer: D Explanation: All three queries retrieve the MySQL server version. Question 59. Which MySQL function can be used to convert a string to a binary string? A) BINARY(str) B) CAST(str AS BINARY) C) CONVERT(str USING binary) D) All of the above Answer: D Explanation: All three syntaxes produce a binary string representation.