Get the App
SLTechnology News&Howtos  ›  Network Security  › 

The difference between char and varchar

Shulou Source: shulou.com Published: 2022-06-01 04:10:56 10月06日 Update

The length of char is fixed, and the length of varchar is variable.

For example: char (5) varchar (5)

When entering char data: there are 5 characters, numbers and Chinese characters, and only 5 can be entered.

When entering varchar data: there are also 5 characters, numbers and Chinese characters, and only 5 characters can be entered.

On the surface, there is no difference between char and varchar.

In fact, when char enters 1 (character, number, Chinese character), five spaces will be occupied.

When varchar inputs 1 (character, number, Chinese character), it will only take up one space.

The reason why (varchar) variable length calculation is slow, because variable length needs to calculate the string length, but char does not need to calculate.

Tags: Input characters numbers Chinese characters length data space nothing the reason string actual surface speed variable occupied Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Linux Shulou Tech Info vpn