MySQL MCQ
MySQL MCQ
4. Which of the following clauses is used to display information that match a given pattern?
a) LIKE
b) WHERE
c) IS
d) SAME
Answer: a
Explanation: The ‘LIKE’ clause filters information that match a given pattern. ‘WHERE’ clause selects
information that is specified by a condition. ‘IS’ is used to match the exact condition specified.
5. What column names are displayed when this SQL command is executed?
SHOW COLUMNS FROM tbl_name LIKE '%name';
a) suffixed with ‘name’
b) prefixed with ‘name’
c) suffixed with ‘%name’
d) prefixed with ‘%name’
Answer: a
Explanation: The wildcard ‘%’ is used to indicate that any number of characters can replace it. All column
names that end in ‘name’ are displayed. Additional information of columns like type and size are listed.
6. The special database that always exists after setting up MySQL in a computer is
a) sampdb b) my_sql c) information_schema d) readme_db
Ans. c
11. What does comparing a known value with NULL result into?
a) zero b) a positive value c) a negative value d) null
Ans. d
12. Which clause is used to sort query elements?
a) GROUP
b) GROUP BY
c) ORDER
d) ORDER BY
Ans. d
14. Suppose you want to select a database named ‘sampledb’ as the default database. Which of the
following commands do you use?
a) SELECT DATABASE()
b) SELECT DATABASE sampledb
c) USE DATABASE sampledb
d) USE sampled
Answer: d
Explanation: ‘USE sampledb’ selects sampledb as the default database. Initially, ‘SELECT DATABASE();’
command displays ‘NULL’, since no database is selected by default. The other two are not valid commands.
15. What does ‘abc’ & ‘xyz’ specify in the following SQL statement?
CREATE TABLE abc (xyz);
a) table name and column specs
b) column specs and table name
c) table name and number of columns
d) table name and number of rows
Ans. a
16. To see the table structure, which of the following SQL commands is issued?
a) DESCRIBE tbl_name
b) VIEW tbl_name
c) SELECT TABLE tbl_name
d) SELECT tbl_name
Ans. a
17. MySQL can be used to execute script files.
a) True b) False
Ans. a
20. To know your MYSQL version and current date which of the following command you should use?
a) VERSION, CURRENT_DATE();
b) SELECT VERSION, CURRENTDATE();
c) SELECT VERSION(), CURRENT_DATE;
d) SELECT VERSON(),CURRENT_DATE();
Ans. c
28. Which of the following is the correct syntax to add a field using alter command?
a) ALTER TABLE table_name ADD field_name data type;
b) ALTER TABLE table_name, field_name data type;
c) ALTER TABLE field_name data type;
d) None of these
Ans. a
29. 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?
a) DELETE
b) TRUNCATE
c) DROP
d) CLEAR
Ans. b
30. Which of the following is the correct syntax for using the TRUNCATE statement?
a) TUNCATE TABLE-NAME;
b) TRUNCATE TABLE-NAME DATABASE-NAME;
c) TRUNCATE TABLE TABLE-NAME;
d) TRUNCATE DATABASE-NAME TABLE-NAME;
Ans. c
31. Suppose you have 1000 records and you only want 100 records which of the following clause you will
use?
a) SET LIMIT
b) LIMIT
c) HAVING
d) GROUP BY
Ans. b
32. Which operator checks whether the particular condition record exists in the table or not?
a) Exists
b) Is null
c) Not null
d) In
Ans. a
33. Which SQL command is used for granting or revoking the rights?
a) DML (Data Manipulation language)
b) DDL (Data definition language)
c) DCL (Data control language)
d) DQL (Data Query Language)
Ans. c
34. Which key helps us to establish the relationship between two tables?
a) Candidate key
b) Foreign key
c) Primary key
d) Unique key
Ans. b
36. Which SQL commands are used for manipulation/ modifying the data present in the table?
a) DML
b) DDL
c) DCL
d) DQL
Ans. a
37. If you want to add a row in a table then which command you will use?
a) INSERT INTO b) ADD
c) ALTER d) CREATE
Ans. a
38. Which of the following data type is used when it comes to store images in your database?
a) BIG INT b) BLOB c) VARCHAR d) INT
Ans. b
39. “CREATE TABLE…” Command is used to create which type of table in MySQL?
a) Permanent Table b) Virtual Table
c) Temporary Table d) All of these
Ans. a
46. How many distinct, different values can you hold in an enum field?
a) 255 b) 7
c) 65535 d) 2
Ans. c
49. In a LIKE clause, you can ask for any 6 letters value by writing:
a) LIKE (That is six underscore characters)
b) LIKE .{6}
c) LIKE ??????
d) LIKE ……
Ans. a
55. Databases are stored in so that they are available when needed.
a) data mines
b) data matrices
c) data sources
d) data dashboards
Ans. b
67. The student marks should not be greater than 100. This is
a) Integrity constraint
b) Referential constraint
c) Over-defined constraint
d) Feasible constraint
Ans. a
78. command makes the updates performed by the transaction permanent in the database?
a) ROLLBACK
b) COMMIT
c) TRUNCATE
d) DELETE
Ans. b
79. A CASE SQL statement is ?
a) A way to establish a loop in SQL
b) A way to establish an IF-THEN-ELSE in SQL
c) A way to establish a data definition in SQL
d) All of these
Ans. b
80. Which of the following is the basic approaches for joining tables?
a) Union JOIN b) Natural JOIN c) Subqueries d) All of these
Ans. d
81. Why we need to create an index if the Primary key is already present in a table?
a) Index improves the speed of data retrieval operations on a table
b) Index are special lookup tables that will be used by the database search engine
c) Indexes are synonyms of a column in a table
d) All of these
Ans. a
82. Group of operations that form a single logical unit of work is known as
a) View b) Network
c) Unit d) Transaction
Ans. d
85. What is the difference between a PRIMARY KEY and a UNIQUE KEY?
a) Primary key can store null value, whereas a unique key cannot store null value
b) We can have only one primary key in a table while we can have multiple unique keys
c) Primary key cannot be a date variable whereas unique key can be
d) None of these
Ans. b
86. When the wildcard in a WHERE clause is useful?
a) When an exact match is required in a SELECT statement
b) When an exact match is not possible in a SELECT statement
c) When an exact match is required in a CREATE statement
d) When an exact match is not possible in a CREATE
statement Ans. b
88. is a program that perform some common action on database data and also stored in the
database.
a) Stored Procedure
b) Trigger
c) Stored Function
d) None of these
Ans. a
91. What does ‘name’ represent in the following SQL code snippet?
CREATE TABLE student
(
name CHAR(30),
roll_num INT,
address CHAR(30),
phone CHAR(12)
);
a) A table b) A row c) A column d) An object
Ans. c
92. The number of attributes in the following SQL table is
CREATE TABLE employee (
emp_name CHAR(30),
emp_id INT
);
a) 30 b) 1 c) 2 d) 3
Ans. c
93. Which MySQL function is used to get the current date and time?
a) DATETIME() b) TODAY()
c) DATE() d) NOW()
Ans. d