Debug School

Akanksha
Akanksha

Posted on

Top 30 MySQL Interview Questions with Answers

1. What does MySQL stand for?

a) My Sequel
b) My Structured Query Language
c) My Server Query Language
d) Multiuser Server Query Language
Answer: b) My Structured Query Language

2. Which of the following is not a MySQL data type?

a) VARCHAR
b) INTEGER
c) STRING
d) FLOAT
Answer: c) STRING

3. What is the maximum length of VARCHAR in MySQL?

a) 255 characters
b) 512 characters
c) 1024 characters
d) 65535 characters
Answer: d) 65535 characters

4. Which command is used to create a new database in MySQL?

a) CREATE
b) ALTER
c) INSERT
d) NEW
Answer: a) CREATE

5. In MySQL, which statement is used to insert new records into a table?

a) ADD
b) INSERT INTO
c) UPDATE
d) SET
Answer: b) INSERT INTO

6. What is the purpose of the SELECT statement in MySQL?

a) To delete data from a table
b) To update data in a table
c) To retrieve data from a table
d) To create a new table
Answer: c) To retrieve data from a table

7. Which MySQL function is used to count the number of rows in a table?

a) COUNT()
b) SUM()
c) AVG()
d) MAX()
Answer: a) COUNT()

8. What is the default port number for MySQL?

a) 3306
b) 3307
c) 8080
d) 5432
Answer: a) 3306

9. Which MySQL statement is used to delete data from a table?

a) DELETE
b) TRUNCATE
c) DROP
d) REMOVE
Answer: a) DELETE

10. Which operator is used for pattern matching in MySQL?

a) LIKE
b) MATCH
c) COMPARE
d) EQUALS
Answer: a) LIKE

11. What is the purpose of the ORDER BY clause in MySQL?

a) To group rows based on a condition
b) To sort rows based on a specified criterion
c) To limit the number of rows returned
d) To join tables together
Answer: b) To sort rows based on a specified criterion

12. Which MySQL function is used to find the highest value in a column?

a) MAX()
b) MIN()
c) AVG()
d) SUM()
Answer: a) MAX()

13. In MySQL, what is a foreign key?

a) A key used for encryption
b) A key that uniquely identifies each row in a table
c) A key that links to a primary key in another table
d) A key used for indexing purposes
Answer: c) A key that links to a primary key in another table

14. Which statement is used to change the value of an existing record in a table in MySQL?

a) UPDATE
b) ALTER
c) MODIFY
d) CHANGE
Answer: a) UPDATE

15. What is the purpose of the GROUP BY clause in MySQL?

a) To order the results in ascending order
b) To group rows based on a condition
c) To filter the results
d) To perform mathematical operations on columns
Answer: b) To group rows based on a condition

16. Which MySQL statement is used to rename a table?

a) ALTER TABLE
b) RENAME TABLE
c) UPDATE TABLE
d) MODIFY TABLE
Answer: b) RENAME TABLE

17. What does the INDEX keyword do in MySQL?

a) Defines a primary key
b) Creates an index on a column
c) Allows NULL values in a column
d) Sets a default value for a column
Answer: b) Creates an index on a column

18. Which MySQL statement is used to add a new column to a table?

a) ADD COLUMN
b) ALTER COLUMN
c) MODIFY COLUMN
d) CHANGE COLUMN
Answer: a) ADD COLUMN

19. What is the purpose of the LIMIT clause in MySQL?

a) To limit the number of rows returned in a query
b) To specify a condition for filtering data
c) To order the results in ascending order
d) To group rows based on a condition
Answer: a) To limit the number of rows returned in a query

20. Which MySQL statement is used to drop a table?

a) DELETE TABLE
b) DROP TABLE
c) REMOVE TABLE
d) TRUNCATE TABLE
Answer: b) DROP TABLE

21. What is the default storage engine in MySQL?

a) InnoDB
b) MyISAM
c) MEMORY
d) CSV
Answer: a) InnoDB

22. Which statement is used to change the data type of a column in MySQL?

a) MODIFY COLUMN
b) ALTER COLUMN
c) CHANGE COLUMN
d) UPDATE COLUMN
Answer: a) MODIFY COLUMN

23. What is the purpose of the HAVING clause in MySQL?

a) To order the results in ascending order
b) To filter rows based on a condition
c) To group rows based on a condition
d) To limit the number of rows returned
Answer: c) To group rows based on a condition

24. Which function is used to calculate the square root in MySQL?

a) SQRT()
b) ROOT()
c) POWER()
d) EXP()
Answer: a) SQRT()

25. In MySQL, what is the function of the CONCAT() function?

a) To concatenate two or more strings
b) To compare two strings
c) To extract a substring from a string
d) To find the length of a string
Answer: a) To concatenate two or more strings

26. Which MySQL statement is used to change the value of an existing record and insert a new record if the record does not exist?

a) UPDATE
b) INSERT
c) REPLACE
d) MODIFY
Answer: c) REPLACE

27. What is the purpose of the TRUNCATE TABLE statement in MySQL?

a) To remove all rows from a table
b) To delete specific rows from a table
c) To drop the table structure
d) To rename the table
Answer: a) To remove all rows from a table

28. Which MySQL statement is used to update multiple columns in a table?

a) UPDATE
b) SET
c) MODIFY
d) CHANGE
Answer: a) UPDATE

29. What is the purpose of the UNIQUE constraint in MySQL?

a) To ensure that a column contains unique values
b) To set a default value for a column
c) To allow NULL values in a column
d) To create an index on a column
Answer: a) To ensure that a column contains unique values

30. Which function is used to retrieve the current date and time in MySQL?

a) NOW()
b) CURRENT_TIMESTAMP()
c) DATE()
d) TIME()
Answer: a) NOW()

31. What is the purpose of the UNION statement in MySQL?

a) To combine the result sets of two or more SELECT statements
b) To join two or more tables based on a condition
c) To order the results in ascending order
d) To group rows based on a condition
Answer: a) To combine the result sets of two or more SELECT statements

Top comments (0)