• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

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.
0
zzl630
Asked:
zzl630
  • 3
  • 2
  • 2
2 Solutions
 
Dave BaldwinFixer 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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 BaldwinFixer 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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now