Difference:
Char: The stored data is fixed-length;
VARCHAR: Stored variable length of data
Example:
Define two data items in the data table char (200) and varchar (200), while depositing the string "Hello Word",
The char type will store these more than 10 characters with these 200 + data lengths, which is very sweaty! ;
The varchar type is available on demand and only stores it in the space required by these more than 10 characters, plus a location to store the location information, well, much better.
Attention:
1. This looks like varchar is much better than Char, does char have merit?
Of course there are!!!
- Char type because of fixed length, so query speed is much faster
- Some data is already very short, with char type more space-saving, varchar type need to store address information, but wasted a certain amount of space
2, since the varchar on demand, then the definition of the data table when the big hard to write it? Error
- When defining a data table, MySQL caches data table information in memory, which is a defined size that wastes space
- Queries are cached in memory, and the length of the cached data is also defined by the length of the data.
So, just come on, the definition of how much definition how big, well, that's it ...
Differences between char and varchar types in MySQL