MySQL Questions and Answers – Choosing Data Types

This set of MySQL Database Multiple Choice Questions & Answers (MCQs) focuses on “Choosing Data Types”.

1. The AUTO_INCREMENT column attribute is best used with which type?
a) FLOAT
b) INT
c) CHARACTER
d) DOUBLE
View Answer

Answer: b
Explanation: The AUTO_INCREMENT is a column attribute and it is best used with the integer datatypes. It automatically assigns monotonically increasing values to the AUTO_INCREMENT columns.

2. Which datatype is best suited to store currency values?
a) INT
b) FLOAT
c) DOUBLE
d) DECIMAL
View Answer

Answer: d
Explanation: Currency is a numeric information. For monetary calculations, FLOAT and DOUBLE are subject to rounding error and may not be suitable. A DECIMAL(M, 2) type is best suited for it.

3. MySQL provides a date type that has an optional time part.
a) True
b) False
View Answer

Answer: b
Explanation: In MySQL, there is no data type provided which has an optional time part. The ‘DATE’ type values never have a time part. The ‘DATETIME’ type values must have a time part in them.
advertisement
advertisement

4. If a column is expected to store values up to 2 million, the best datatype for it is _____________
a) SMALLINT
b) TINYINT
c) MEDIUMINT
d) BIGINT
View Answer

Answer: d
Explanation: The different numeric types used in MySQL are used to store different range of values. To store values of the order of a million, the MEDIUMINT or BIGINT datatype is sufficient.

5. Which of these types store the longest length of strings?
a) CHAR
b) VARCHAR
c) TINYTEXT
d) TEXT
View Answer

Answer: d
Explanation: in MySQL, the different string datatypes are used to store different lenghts of the string. Here, the length would refer to the number of characters in the string. TEXT stores longer strings.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. AUTO_INCREMENT columns must be NOT NULL.
a) True
b) False
View Answer

Answer: a
Explanation: The ‘AUTO_INCREMENT’ columns must be NOT NULL. If the NOT NULL is omitted, MySQL adds it automatically. AUTO_INCREMENT column values begin with 1 and increase monotonically after it.

7. Which of these values is not valid as an AUTO_INCREMENT value?
a) 0
b) 1
c) 2
d) 3
View Answer

Answer: a
Explanation: In MySQL, the ‘AUTO_INCREMENT’ values are a sequence of unique values assigned to the columns such that they increase monotonically. They begin with the value 1 and increment by a unit.
advertisement

8. If an integer column is used for the values in range 1 to 99999, the best suitable datatype is ____________
a) MEDIUMINT SIGNED
b) MEDIUMINT UNSIGNED
c) SMALLINT SIGNED
d) SMALLINT UNSIGNED
View Answer

Answer: b
Explanation: Since the range starts from the positive value 1, it is best to keep the datatype as UNSIGNED. The maximum value is of the order of 10^5, so a MEDIUMINT datatype is well suited.

9. INT2 maps to MySQL type _____________
a) TINYINT
b) SMALLINT
c) MEDIUMINT
d) BIGINT
View Answer

Answer: b
Explanation: In order to facilitate the use of code written for SQL implementations from other vendors, MySQL maps the data types from the other vendor types to the appropriate MySQL type.
advertisement

10. INT3 maps to MySQL type _____________
a) TINYINT
b) SMALLINT
c) MEDIUMINT
d) BIGINT
View Answer

Answer: c
Explanation: In order to facilitate the use of the code written for SQL implementations (reusability of code) from other vendors, MySQL maps the data types from the other vendor types to the appropriate MySQL type.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.