Learn MYSQL MCQs
Prepare MYSQL MCQs (Multiple choice Questions) for exam and job interviews.
How can you add a new column to an existing MySQL table?
1) ALTER TABLE table_name ADD new_column_name data_type;
2) MODIFY TABLE table_name ADD new_column_name data_type;
3) CHANGE TABLE table_name ADD new_column_name data_type;
4) APPEND COLUMN new_column_name TO table_name;
Answer : Option 1
What is the default port number for MySQL?
1) 3306
2) 5432
3) 8080
4) 1521
Answer : Option 1
Which statement is used to create a foreign key in MySQL?
1) CREATE FOREIGN KEY (column_name);
2) ADD FOREIGN KEY (column_name);
3) ALTER TABLE table_name ADD CONSTRAINT fk_name FOREIGN KEY (column_name);
4) INSERT FOREIGN KEY (column_name);
Answer : Option 3
How do you remove all records from a table without removing the table structure?
1) DELETE FROM table_name;
2) TRUNCATE TABLE table_name;
3) CLEAR TABLE table_name;
4) DROP TABLE table_name;
Answer : Option 2
What is the function of the SQL DATE_FORMAT() function?
1) Formats date values based on the specified format
2) Calculates the difference between dates
3) Converts a string to date
4) Extracts the year from a date
Answer : Option 1
Which statement is used to create an index in MySQL?
1) CREATE INDEX index_name ON table_name (column_name);
2) ADD INDEX index_name TO table_name (column_name);
3) SET INDEX index_name FOR table_name (column_name);
4) DEFINE INDEX index_name IN table_name (column_name);
Answer : Option 1
What does the SQL INNER JOIN keyword do?
1) Returns records with matching values in both tables
2) Returns all records from one table
3) Returns records with no matching values
4) Returns all records regardless of matching
Answer : Option 1
How do you find the maximum value in a column?
1) SELECT MAX(column_name) FROM table_name;
2) SELECT HIGH(column_name) FROM table_name;
3) SELECT TOP(column_name) FROM table_name;
4) SELECT HIGHEST(column_name) FROM table_name;
Answer : Option 1
What is the purpose of the SQL SUBSTRING() function?
1) Extracts a substring from a string
2) Finds the length of a string
3) Concatenates strings
4) Converts a string to uppercase
Answer : Option 1
How do you add a primary key to an existing MySQL table?
1) ALTER TABLE table_name ADD PRIMARY KEY (column_name);
2) MODIFY TABLE table_name ADD PRIMARY KEY (column_name);
3) CHANGE TABLE table_name ADD PRIMARY KEY (column_name);
4) SET PRIMARY KEY ON table_name (column_name);
Answer : Option 1