Learn MYSQL MCQs

Prepare MYSQL MCQs (Multiple choice Questions) for exam and job interviews.

How do you set a default value for a column in MySQL?

1) ALTER TABLE table_name ALTER column_name SET DEFAULT value;

2) CREATE TABLE table_name (column_name data_type DEFAULT value);

3) SET DEFAULT column_name=value;

4) ALTER TABLE table_name CHANGE column_name column_name data_type DEFAULT value;

Answer : Option 2

Which function is used to convert a string to an integer in MySQL?

1) CONVERT()

2) CAST()

3) TO_NUMBER()

4) INT()

Answer : Option 2

What does the SQL SHOW DATABASES command do?

1) Displays all databases on the MySQL server

2) Creates a new database

3) Deletes a database

4) Updates a database

Answer : Option 1

How do you add a comment to your SQL code?

1) -- This is a comment

2) # This is a comment

3) /* This is a comment */

4) All of the above

Answer : Option 4

What does the SQL CHAR_LENGTH() function return?

1) The number of characters in a string

2) The number of bytes used by a string

3) The number of words in a string

4) The maximum length of a string

Answer : Option 1

Which command is used to lock a table in MySQL?

1) LOCK TABLE table_name;

2) TABLE LOCK table_name;

3) SET LOCK table_name;

4) ALTER TABLE table_name LOCK;

Answer : Option 1

How do you retrieve the current date and time in MySQL?

1) SELECT NOW();

2) SELECT CURRENT_DATE_TIME();

3) SELECT GET_DATE();

4) SELECT TIME();

Answer : Option 1

What is a temporary table in MySQL?

1) A table that exists temporarily during a session

2) A table that is permanently deleted

3) A backup table

4) An index table

Answer : Option 1

How do you prevent SQL injection in MySQL?

1) Use prepared statements

2) Use regular expressions

3) Escape all inputs

4) All of the above

Answer : Option 4

Which command is used to unlock a table in MySQL?

1) UNLOCK TABLE table_name;

2) TABLE UNLOCK table_name;

3) SET UNLOCK table_name;

4) ALTER TABLE table_name UNLOCK;

Answer : Option 1