MySQL is the most common open-source software, nowadays every other person relies on MySQL for its database. As it is open source so anyone in this world can use this system. This system is developed by ORACLE cooperation.
MySQL MCQs: This section contains multiple-choice questions and answers on the various topics of MySQL. Practice these MCQs to test and enhance your skills on MySQL.
List of MySQL MCQs
1. In which language MYSQL is written?
- PYTHON
- C/C+
- JAVA
- COBOL
Answer: B) C/C++
Explanation:
2. To see the list of options provided by MYSQL which of the following command is used?
- HELP
- –HELP
- — HELP
- ELP-
Answer: C) — HELP
Explanation:
To see the list of options provided by MYSQL we use — HELP.
3. What do you mean by HOST in MYSQL?
- HOST is the user name.
- HOST is the representation of where the MYSQL server is running.
- HOST is the administration’s machine name.
Answer: B) HOST is the representation of where the MYSQL server is running.
Explanation:
HOST is the representation of where the MYSQL server is running.
4. Is a semicolon necessary after every query?
- TRUE
- FALSE
Answer: A) TRUE
Explanation:
It is important to put a semicolon after every query.
5. To know your MYSQL version and current date which of the following command you should use?
- VERSION, CURRENT_DATE();
- SELECT VERSION, CURRENTDATE();
- SELECT VERSION(), CURRENT_DATE;
- SELECT VERSON(),CURRENT_DATE();
Answer: C) SELECT VERSION (), CURRENT_DATE;
Explanation:
SELECT VERSION (), CURRENT_DATE; is the command to check the current MYSQL version and date.
6. In which form MYSQL query results are displayed?
- LIST
- TUPLE
- ROWS AND COLUMNS
- LIST AND TUPLES BOTH
Answer: C) ROWS AND COLUMNS
Explanation:
MYSQL query results are displayed in the form of ROWS AND COLUMNS.
7. What does the marked time represent in the given picture?
- CPU TIME
- MACHINE TIME
- WALL CLOCK TIME
Answer: C) WALL CLOCK TIME
Explanation:
The time marked in the picture represents the WALL CLOCK TIME because this time is affected by server load and network latency.
8. In MYSQL, can we write keywords in any letter case?
- YES
- NO
Answer: A) YES
Explanation:
YES, in MYSQL we can write keywords in any letter case.
9. In MYSQL, can you write multiple statements in a single line?
- YES
- NO
Answer: A) YES
Explanation:
YES, we can write multiple statements in a single line, we just have to separate them with a semicolon.
10. If you want to stop the processing query then which of the following command you should use?
- QUIT
- STOP
- /c
- C and D both
Answer: C) /c
Explanation:
To stop the processing query the /c command is used.
11. To see all the databases which command is used?
- Show database;
- Show databases;
- Show database();
- Show_all database;
Answer: B) Show databases;
Explanation:
To see all the databases SHOW DATABASES; command is used.
12. Can we create a database named 01_test?
- Yes
- No
Answer: A) Yes
Explanation:
Yes we can create a database named 01_test.
13. In the following statement, what do you mean by the ‘student’?
USE student;
- Database name
- Row name
- Column name
- Table name
Answer: A) Database name
Explanation:
In USE student, ‘student’ represents the database named.
14. If our database name is ‘schooldb’ and we want to drop this database will the query work if we will write our database name in capital letters?
- Yes
- No
Answer: A) Yes
Explanation:
We can write any case while using a drop statement.
15. Which of the following command is used to delete a database?
- DELETE DATABASE_NAME;
- DROP DATABASE_NAME;
- DROP DATABASE DATABASE_NAME;
- DELETE DATABASE DATABASE_NAME;
Answer: C) DROP DATABASE DATABASE_NAME;
Explanation:
DROP DATABASE DATABASE_NAME; command is used to delete a database.
16. ALTER command is a type of which SQL command?
- DML
- DDL
- DCL
- DQL
Answer: B) DDL
Explanation:
ALTER command is a type DDL (data definition language) SQL command.
17. Which of the following is the correct syntax to add a field using alter command?
- ALTER TABLE table_name ADD field_name data type;
- ALTER TABLE table_name, field_name data type;
- ALTER TABLE field_name data type;
Answer: A) ALTER TABLE table_name ADD field_name data type;
Explanation:
To add a field using alter statement following syntax should be followed:
ALTER TABLE table_name ADD field_name data type;
18. Can you change the column name using alter command?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, we can easily change the column name using alter command.
19. Suppose you have a table named to test and inside this table you have a column named CGPA now if you are asked to change the column named CGPA to total percentage, using alter command then which of the following statement you will write?
- ALTER TABLE test CHANGE COLUMN ‘cgpa’ ‘total_percentage’ int;
- ALTER test table CHANGE ‘cgpa’ ,’total_percentage’ int;
- ALTER TABLE test CHANGE ‘cgpa ‘total_percentage’ int;
Answer: A) ALTER TABLE test CHANGE COLUMN ‘cgpa’ ‘total_percentage’ int;
Explanation:
we will use the following syntax,
ALTER TABLE test CHANGE COLUMN ‘cgpa’ ‘total_percentage’ int;
20. Suppose you are asked to drop a column using alter statement then which syntax you will follow?
- ALTER table_name TABLE DROP COLUMN column_name;
- ALTER TABLE table_name DROP COLUMN column_name;
Answer: B) ALTER TABLE table_name DROP COLUMN column_name;
Explanation:
we will use the following syntax,
ALTER TABLE table_name DROP COLUMN column_name;
21. What does the show tables command do?
- It displays all the tables of all the databases in the machine.
- It displays all the tables of a particular database.
- It only displays the current table.
Answer: B) It displays all the tables of a particular database.
Explanation:
show tables command displays all the tables of a particular database.
22. Is it important to provide where condition with update statement in MYSQL?
- YES
- NO
Answer: A) YES
Explanation:
YES it is important to provide the where condition with an update statement else the entire column will have the same updated value.
23. Suppose you have two columns named student_name and student_department inside table student_details and you are asked to update the value of these two columns where ID=4 then what statement you will write?
- UPDATE student_details SET Student_name=”ram”, Student_department=’Chemical’ WHERE ID=’4′;
- UPDATE table student_details SET column_name Student_name=”ram”, Student_department=’Chemical’ WHERE ID=’4′;
- UPDATE student_details SET Student_name=”ram” and Student_department=’Chemical’ WHERE ID=’4′;
Answer: A) UPDATE student_details SET Student_name=”ram”, Student_department=’Chemical’ WHERE ID=’4′;
Explanation:
According to the given situation we will write,
UPDATE student_details SET Student_name=”ram”, Student_department=’Chemical’ WHERE ID=’4′;
24. What is the function of DESCRIBE statement?
- This statement helps us to get the details of the entire row.
- This statement helps us to get the definition of a particular table at a time.
- This statement helps us to get the definition of all the tables.
Answer: B) This statement helps us to get the definition of a particular table at a time.
Explanation:
DESCRIBE statement helps us to get the definition of a particular table at a time, it tells us about all the constraints which are applied to columns.
25. If you are asked to delete the entire data of a table without disturbing the table definition then in such case which statement you will use?
- DELETE
- TRUNCATE
- DROP
- CLEAR
Answer: B) TRUNCATE
Explanation:
To only remove the data of the table without disturbing the definition of the table we use the TRUNCATE statement, this statement helps us to delete all the data of a table.
26. Which of the following is the correct syntax for using the TRUNCATE statement?
- TUNCATE TABLE-NAME;
- TRUNCATE TABLE-NAME DATABASE-NAME;
- TRUNCATE TABLE TABLE-NAME;
- TRUNCATE DATABASE-NAME TABLE-NAME;
Answer: C) TRUNCATE TABLE TABLE-NAME;
Explanation:
The correct syntax to use truncate statement is,
TRUNCATE TABLE TABLE-NAME;
27. From all the clauses in MYSQL what task is performed by the DISTINT clause?
- It returns us the duplicate values
- It returns us the unique values
- It returns us the NULL values;
Answer: B) It returns us the unique values
Explanation:
If we only want to keep unique records then in that case we can simply use the DISTINCT Clause.
28. Suppose you have 1000 records and you only want 100 records which of the following clause you will use?
- SET LIMIT
- LIMIT
- HAVING
- GROUP BY
Answer: B) limit clause
Explanation:
The LIMIT clause helps us to set a limit to records we want in return as a result.
29. What will the following statement return?
SELECT * FROM student_details WHERE Student_name LIKE ‘S%’;
Where student_details is the table name and student_name is the column name?
- It will return the name starting with s
- It will return the name ending with s
- It will return the name who has s in between
Answer: A) It will return the name starting with s
Explanation:
The statement will return the name starting with s
30. Suppose you are asked to display all the names which have ‘a’ as their second character then which query pattern you will use?
- _ _ a%;
- _a_;
- _a%;
- _%a;
Answer: C) _a%;
Explanation:
To know the name who has an as its second character we will write: _a%;
31. If you are asked to find out the names which only have 5 characters then what query pattern you will use?
- %%%%%
- _%_%_
- _____
- –%%-
Answer: C) _____
Explanation:
If we are asked to find out the names which only have 5 characters, we will put 5 underscores _____.
32. State whether the statement is true or false? ‘PRIMARY KEY and UNIQUE KEY both are the same’
- TRUE
- FALSE
Answer: B) FALSE
Explanation:
No, UNIQUE key and PRIMARY both are different in many ways.
33. Can we have more than 1 primary key in a table?
- TRUE
- FALSE
Answer: B) FALSE
Explanation:
No, in a table we can only have 1 primary key.
34. A variable that has a primary key constraint can have any data type other than INT?
- TRUE
- FALSE
Answer: B) FALSE
Explanation:
PRIMARY KEY constraints should always have a numerical value.
35. Which key is commonly known as a subset of a super key?
- Candidate key
- Foreign key
- Primary key
- Unique key
Answer: A) Candidate key
Explanation:
Candidate key is commonly known as a subset of the super key.
36. Numbers of super keys always more than the number of candidate keys?
- True
- False
Answer: A) True
Explanation:
The super key is the super set so therefore we can have many super keys in a table
37. Which key is the minimal set of super keys?
- Candidate key
- Foreign key
- Primary key
- Unique key
Answer: A) Candidate key
Explanation:
Candidate key is the minimal set of super keys.
38. Which key helps us to establish the relationship between two tables?
- Candidate key
- Foreign key
- Primary key
- Unique key
Answer: B) Foreign key
Explanation:
Foreign key helps us to establish the relationship between two tables.
39. Super key and candidate key can have NULL values?
- True
- False
Answer: A) True
Explanation:
The only similarity between super key and candidate key is that they both can have NULL as their values.
40. Which operator checks whether the particular condition record exists in the table or not?
- Exists
- Is null
- Not null
- In
Answer: A) Exists
Explanation:
The EXISTS operator checks whether the particular condition record exists in the table or not.
41. By default, the result of an order by clause is always displayed in which order?
- Ascending
- Descending
Answer: A) Ascending
Explanation:
By default, the result is always displayed in ascending order.
42. Which of the following syntax you will use to rename the table name?
- ALTER TABLE table_name RENAME TO new_table_name;
- RENAME new_table_name;
- ALTER table_name RENAME new_table_name;
Answer: A) ALTER TABLE table_name RENAME TO new_table_name;
Explanation:
To rename the table we will use:
ALTER TABLE table_name RENAME TO new_table_name;
43. ‘MYSQL is the open source software’ – What do you mean by this statement?
- This means anyone can use this software.
- This means you can contact the source of the software
- This means it gives the best security features
Answer: A) This means anyone can use this software.
Explanation:
An open-source software means anyone in this world can use this software, can inspect this software, and also modify it.
44. Which SQL command is used for granting or revoking the rights?
- DML
- DDL
- DCL
- DQL
Answer: C) DCL
Explanation:
Generally known as Data Control Language. These commands are used for granting or revoking the rights.
45. Which MySQL function is used to get the current date and time?
- DATETIME()
- TODAY()
- DATE()
- NOW()
Answer: D) NOW()
Explanation:
The NOW() function is used to get the current date and time in MySQL.
46. SELECT is a type of which SQL command?
- DML
- DDL
- DCL
- DQL
Answer: D) DQL
Explanation:
SELECT is a type of DQL command usually known as Data Query Language.
47. Which SQL commands are used for manipulation/ modifying the data present in the table?
- DML
- DDL
- DCL
- DQL
Answer: A) DML
Explanation:
Commonly known as Data Manipulation Language. As the name suggests, these commands are used for manipulation/ modifying the data present in the table.
48. If you want to add a row in a table then which command you will use?
- INSERT INTO
- ADD
- ALTER
- CREATE
Answer: A) INSERT INTO
Explanation:
INSERT INTO command helps us to add a row in a table.
49. Which type of join combines the result from both the tables and returns us the Cartesian product of the values?
- Right join
- Left join
- Inner join
- Cross join
Answer: D) Cross join
Explanation:
CROSS JOIN combines all the data from the first table and the second table. The result obtained through this join is the Cartesian product like every value will be multiplied with every other value of another table.
50. Which of the following data type is used when it comes to store images in your database?
- BIG INT
- BLOB
- VARCHAR
- INT
Answer: B) BLOB
Explanation:
These are commonly known as binary large objects. This data type (MySQL Data Types) is really important when you have to store a large set of binary data. As we have seen images have large addresses, so to store them we can use this data type. BLOB is case-sensitive. It can store up to 65535 bytes of data.