Learn MYSQL MCQs

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

How do you add a primary key to an existing table?

1) ALTER TABLE table_name ADD PRIMARY KEY (column_name);

2) MODIFY TABLE table_name ADD PRIMARY KEY (column_name);

3) SET PRIMARY KEY (column_name) IN table_name;

4) CREATE PRIMARY KEY column_name IN table_name;

Answer : Option 1

Which SQL command is used to remove duplicate rows?

1) DELETE DUPLICATES FROM table_name;

2) SELECT DISTINCT columns FROM table_name;

3) REMOVE DUPLICATES FROM table_name;

4) UNIQUE rows FROM table_name;

Answer : Option 2

What is the purpose of the MySQL command GROUP BY?

1) To aggregate data across multiple records

2) To sort records

3) To filter records

4) To limit results

Answer : Option 1

What data type is best for storing true/false values in MySQL?

1) TINYINT

2) BOOLEAN

3) BIT

4) YESNO

Answer : Option 1

Which operator is used to compare a value against a list of values?

1) BETWEEN

2) IN

3) LIKE

4) ANY

Answer : Option 2

How can you prevent duplicate entries in a MySQL column?

1) Using UNIQUE constraint

2) Using NOT NULL constraint

3) Using PRIMARY KEY

4) Using DEFAULT value

Answer : Option 1

Which function returns the number of rows in a MySQL table?

1) COUNT(*)

2) SUM(*)

3) TOTAL(*)

4) ROWS(*)

Answer : Option 1

What is the default port number for MySQL?

1) 3306

2) 5432

3) 8080

4) 1521

Answer : Option 1

What is the command to rename a column in a MySQL table?

1) ALTER TABLE table_name RENAME column_name TO new_column_name;

2) MODIFY TABLE table_name CHANGE column_name new_column_name;

3) RENAME COLUMN column_name TO new_column_name IN table_name;

4) CHANGE COLUMN column_name TO new_column_name IN table_name;

Answer : Option 2

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

1) ALTER TABLE table_name MODIFY column_name SET DEFAULT value;

2) ALTER TABLE table_name CHANGE column_name SET DEFAULT value;

3) ALTER TABLE table_name ADD column_name DEFAULT value;

4) ALTER TABLE table_name MODIFY column_name SET value;

Answer : Option 1