Home  >  Article  >  Database  >  varchar maximum length

varchar maximum length

(*-*)浩
(*-*)浩Original
2019-07-24 11:42:2513719browse

VARCHAR(M) is a more flexible data type than CHAR. It is also used to represent character data, but VARCHAR can save variable-length strings. Where M represents the maximum length of the string allowed to be saved by this data type. As long as the length of the string is less than the maximum value, it can be saved in this data type.

varchar maximum length

# Therefore, it is more sensible to use the VARCHAR data type for those data objects whose exact length is difficult to estimate. (Recommended learning: MySQL Video Tutorial)

Before MySQL 4.1, the maximum length supported by the VARCHAR data type was 255, and versions above 5.0 supported 65535 bytes in utf8 encoding. Supports up to 21843 characters (not empty).

varchar features

1. It takes up less storage space than the fixed-length type (char) (except for MyISAM tables created using ROW_FORMAT=FIXED).

2. Use additional 1-2 bytes to store the value length. Use 1 byte for column length

3. Save space, so performance will be helpful. Additional work will be incurred when updating.

4. In versions 5.0 and above, the spaces at the end of the string will be saved when the value is taken or set. Versions before 4.1 will delete the spaces at the end of the string.

5. The maximum length is much larger than the average length. It is suitable to use varchar when updates rarely occur because there are fewer fragments.

Another outstanding benefit of the VARCHAR field is that it takes up less memory and hard disk space than the CHAR field. When the database is large, this memory and disk space saving will become very important.

Although VARCHAR is more flexible to use, from the perspective of the performance of the entire system, the processing speed of the CHAR data type is faster Fast, sometimes even exceeding 50% of the processing speed of VARCHAR. Therefore, users should consider all factors when designing a database in order to achieve the best balance.

For more MySQL related technical articles, please visit the MySQL Tutorial column to learn!

The above is the detailed content of varchar maximum length. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn