✅Top MySQL Interview Questions for Software Testers
🔹 1. What is SQL and how is it used in testing?
Answer: SQL (Structured Query Language) is used to interact with databases. Testers use SQL
to:
Validate data in tables
Verify test results
Perform backend testing
Write queries for data retrieval and validation
🔹 2. What are the different types of SQL statements?
DDL (Data Definition Language): CREATE, ALTER, DROP
DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE
DCL (Data Control Language): GRANT, REVOKE
TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
🔹 3. What is a primary key and foreign key?
Primary Key: Uniquely identifies each record in a table. Cannot be NULL or
duplicate.
Foreign Key: A column that refers to the primary key in another table to create a
relationship.
🔹 4. What are Joins? Name the types.
Joins are used to retrieve data from multiple tables based on relationships.
Types: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, SELF JOIN, CROSS JOIN.
🔹 5. What is the difference between DELETE, TRUNCATE, and DROP?
Command Deletes Data Affects Structure Rollback Possible
DELETE ✅ Yes ❌ No ✅ Yes
TRUNCATE ✅ Yes (All) ❌ No ❌ No
DROP ✅ Yes ✅ Yes ❌ No
🔹 6. What is the use of WHERE clause in SQL?
The WHERE clause filters records based on a condition.
Example: SELECT * FROM users WHERE age > 25;
🔹 7. What is the difference between UNION and UNION ALL?
UNION removes duplicates.
UNION ALL includes all duplicates.
🔹 8. What is the use of DISTINCT keyword?
It is used to return only unique values from a column.
Example: SELECT DISTINCT country FROM customers;
🔹 9. What are constraints in MySQL?
Constraints enforce rules on data in tables.
Examples: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT
🔹 10. How do you perform backend testing using SQL?
Validate data inserted through the UI
Check if data integrity is maintained
Write queries to verify test cases
Compare front-end values with DB values
🔹 11. What are aggregate functions?
Used to perform calculations on multiple rows:
SUM(), AVG(), COUNT(), MAX(), MIN()
🔹 12. What is normalization?
Normalization is the process of organizing data to reduce redundancy.
Common forms: 1NF, 2NF, 3NF.
🔹 13. What is an index in MySQL?
An index improves the speed of data retrieval. However, it may slow down insert/update
operations.
🔹 14. How do you handle NULL values in SQL?
Using IS NULL or IS NOT NULL.
Example: SELECT * FROM users WHERE address IS NULL;
🔹 15. What is a subquery?
A subquery is a query inside another query.
Example:
sql
CopyEdit
SELECT name FROM employees
WHERE dept_id = (SELECT dept_id FROM departments WHERE dept_name = 'HR');