Differences between char and varchar types in MySQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.