Learn MYSQL MCQs

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

Which command is used to change a user’s password in MySQL?

1) ALTER USER user_name IDENTIFIED BY "new_password";

2) UPDATE USER user_name SET PASSWORD="new_password";

3) CHANGE USER user_name TO "new_password";

4) MODIFY USER user_name PASSWORD="new_password";

Answer : Option 1

How do you create a composite primary key in MySQL?

1) CREATE TABLE table_name (column1 data_type, column2 data_type, PRIMARY KEY (column1, column2));

2) ALTER TABLE table_name ADD PRIMARY KEY (column1, column2);

3) SET PRIMARY KEY (column1, column2) ON table_name;

4) CREATE TABLE table_name (column1 data_type, column2 data_type, UNIQUE (column1, column2));

Answer : Option 1

What does the SQL IFNULL() function do?

1) Returns the first argument if it is not NULL, otherwise returns the second argument

2) Checks if a value is NULL

3) Converts NULL to 0

4) Replaces NULL values with empty strings

Answer : Option 1

Which command is used to set a variable in MySQL?

1) SET @variable_name = value;

2) DEFINE variable_name = value;

3) DECLARE variable_name = value;

4) CREATE variable_name = value;

Answer : Option 1

What is the purpose of the SQL TRIM() function?

1) Removes whitespace from both sides of a string

2) Finds the length of a string

3) Converts a string to uppercase

4) Concatenates strings

Answer : Option 1

Which function is used to convert a string to lowercase in MySQL?

1) LOWER()

2) LOW()

3) TO_LOWER()

4) LCASE()

Answer : Option 1

How do you find records with NULL values in a column?

1) SELECT * FROM table_name WHERE column_name IS NULL;

2) SELECT * FROM table_name WHERE column_name = NULL;

3) SELECT * FROM table_name WHERE column_name IS EMPTY;

4) SELECT * FROM table_name WHERE column_name NOT PRESENT;

Answer : Option 1

Which command is used to modify an existing column in MySQL?

1) ALTER TABLE table_name MODIFY column_name data_type;

2) CHANGE TABLE table_name CHANGE column_name data_type;

3) UPDATE TABLE table_name SET column_name = data_type;

4) MODIFY TABLE table_name ALTER column_name data_type;

Answer : Option 1

What does the SQL DATE_ADD() function do?

1) Adds a time interval to a date

2) Subtracts a time interval from a date

3) Formats a date

4) Extracts the year from a date

Answer : Option 1

Which SQL command is used to remove a database?

1) DROP DATABASE database_name;

2) DELETE DATABASE database_name;

3) REMOVE DATABASE database_name;

4) CLEAR DATABASE database_name;

Answer : Option 1