MySQL SQL - What Are the Differences between CHAR and VARCHAR
Interview Question Database For Software Developers
|
|
| What Are the Differences between CHAR and VARCHAR | | What Are the Differences between CHAR and VARCHAR? - MySQL FAQs - Introduction to SQL Basics | | By: FYIcenter.com | CHAR and VARCHAR are both ASCII character data types by default.
But they have the following major differences:
- CHAR stores values in fixed lengths.
Values are padded with space characters to match the specified length.
- VARCHAR stores values in variable lengths.
Values are not padded with any characters. But 1 or 2 extra bytes are added
to store the length of the data.
The table below shows you a good comparison of CHAR and VARCHAR data types:
Value CHAR(4) Length
'' ' ' 4 bytes
'ab' 'ab ' 4 bytes
'abcd' 'abcd' 4 bytes
Value VARCHAR(4) Length
'' '' 1 byte
'ab' 'ab' 3 bytes
'abcd' 'abcd' 5 bytes
| | ID: 1057 | Rank: 1073 | Votes: 0 | Views: 44 | Submitted: 20070511 |
Copyright © 2009 FYIcenter.com
All rights in the contents of this Website are reserved by the individual author.
No part of the contents may be reproduced in any form without author's permission.
|
|
|