MySQL Questions and Answers – Choosing Data Types for Efficient Queries

This set of Basic MySQL Questions and Answers focuses on “Choosing Data Types for Efficient Queries”.

1. Calculations involving numbers are faster than those involving string.
a) True
b) False
View Answer

Answer: a
Explanation: Numbers can be compared in a single operation while string comparisons involve several byte by byte or character by character comparisons. As the strings become longer, the performance gets poor.

2. To convert an int to string, the function is _________________
a) INET_ATON()
b) INET_NTOA()
c) INET_ITOS()
d) INET_STOI()
View Answer

Answer: b
Explanation: In MySQL, the function used to convert an integer to a string is INET_NTOA(). On the other hand, the function INET_ATON() converts a string to the corresponding integer value.

3. To convert a string to an int, the function is _________________
a) INET_ATON()
b) INET_NTOA()
c) INET_ITOS()
d) INET_STOI()
View Answer

Answer: a
Explanation: In MySQL, the function used to convert a string to an integer is INET_ATON(). On the other hand, the function INET_NTOA() converts a string to the corresponding integer value.
advertisement
advertisement

4. To maintain performance of tables having variable length rows, which statement is used?
a) MAINTAIN TABLE
b) BALANCE TABLE
c) ADJUST TABLE
d) OPTIMIZE TABLE
View Answer

Answer: d
Explanation: In the variable length rows, there is more fragmentation of the table on which many deletes or updates are performed. OPTIMIZE TABLE is run periodically to maintain performance.

5. Which of these columns are faster?

Variable length, Fixed length
Note: Join free Sanfoundry classes at Telegram or Youtube

a) same
b) variable length
c) fixed length
d) indeterminate
View Answer

Answer: c
Explanation: The fixed length columns are faster and take more space. CHAR(n) columns take n characters per value because the values are padded with trailing spaces when stored in the table.

6. Which of these take more space?

Variable length columns, Fixed length columns
advertisement

a) variable length
b) same
c) fixed length
d) indeterminate
View Answer

Answer: c
Explanation: In MySQL, the fixed length columns are faster and take more space. CHAR(n) columns take n characters per value because the values are padded with trailing spaces when stored in the table.

7. To minimize disk I/O, which of these should be chosen?

CHAR, VARCHAR
advertisement

a) CHAR
b) VARCHAR
c) CHAR & VARCHAR
d) Either CHAR or VARCHAR
View Answer

Answer: b
Explanation: In MySQL, because CHAR on average takes more space than VARCHAR, VARCHAR is preferred to be used to minimize the amount of the storage and disk I/O needed to process the rows.

8. Avoiding NULL in columns may make queries simpler.
a) True
b) False
View Answer

Answer: a
Explanation: In MySQL, avoiding the NULL in columns may make the queries simpler, since it is not required to check for NULL as a special case. Simpler queries generally can be processed more quickly.

9. Which of these can be used to generate hash values?
a) MS5()
b) MA5()
c) MF5()
d) MD5()
View Answer

Answer: d
Explanation: The hash values can be generated by using the function: MD5(). SHA1() or CRC32() can also be used to do the same. Custom hash values can also be created using logic within the application.

10. IP numbers can be represented as _________________
a) both integers and a string
b) a string but not integers
c) integers but not a string
d) neither a string nor integers
View Answer

Answer: a
Explanation: The IP addresses like 192.168.0.1 can be either stored as a string or a group of integers. Both of these forms would have their own benefits. For example, storing as a string would facilitate pattern matching.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice basic questions and answers on all areas of MySQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

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.