MySQL Char and Varchar question

Hello,
I am some questions about Char and Varchar when I am preparing MySQL administrator test.

1.Suppose you have a column in which most records are going to be between 30 and 32 characters.
Which of the following column types would be most efficient?
A. VARCHAR
B. CHAR
C. TEXT
D. Either VARCHAR or CHAR
Answer: B

I don't know why answer would be Char. Since Char will use Char(32), Varchar will use 30 characters plus 1 byte or 31 characters plus 1 byte or 32 character plus 1 byte. There isn't much difference,  so I think either Varchar or Char will work.


QUESTION NO: 29
You are using a multi-byte character set with variable-length encoding. You need to store records
whose values are always 20 characters. Which of the following column types would be the most
efficient to use in terms of storage space?
A. CHAR
B. VARCHAR
C. The storage requirements for CHAR or VARCHAR would be the same
Answer: B

Since Varchar will take one extra byte for store the length. I thought no doubt should pick Char.


QUESTION NO: 30
Another user has gotten a lock using GET_LOCK. You inquire on the status of the lock by using
A. RELEASE_LOCK
B. IS_FREE_LOCK
C. IS_USED_LOCK
D. Another GET_LOCK
E. LOCK TABLES
Answer: A

The question is asking for status of the lock. I thought B is more appropriate since IS_FREE_LOCK will return 1 if the name is not locked, 0 if it is locked.

I don't now there answers were messed up or I made some mistakes. Appreciate your comments.
zzl630Asked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
CHAR accepts only single byte characters which limits it to character sets that only use 0 to 255.  VARCHAR can accept multi-byte character sets like Unicode which can have up to 3 bytes for a single character.  VARCHAR can have more overhead because of having to handle the multi-byte character sets which can have characters from 1 to 3 bytes in length.  http://dev.mysql.com/doc/refman/5.1/en/char.html

I don't know about the LOCK.
0
 
maeltarCommented:
Is it cheating asking questions for an exam ????

http://www.slideshare.net/jathinshai/310810-exam-questions
0
 
Dave BaldwinFixer of ProblemsCommented:
@maeltar, that link is a 'cheat sheet' if you want to call it that because the correct answers are included in the text.  This question is about Why in preparation for the test so I don't think it's a problem here.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
maeltarCommented:
Ahh sorry, misread
0
 
zzl630Author Commented:
Thanks for your answer Dave.
That make sense for question 2.
So question 1, can I understand as for same or similar length of column, Char has obvious better performance than Varchar?
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
Char can have better performance than Varchar because Char is always 1-byte characters where Varchar can be more and that requires more processing.
0
 
zzl630Author Commented:
That is what I want to know. Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.