MySQL Interview Questions-What is the difference between char and varchar data types in MySQL?

What is the difference between char and varchar data types in MySQL?

  • The char and varchar types are similar, but they are stored and retrieved differently. Their maximum length and whether trailing spaces are preserved are also different. No case conversion is performed during storage or retrieval.
  • Char type query efficiency is relatively high, varchar type is relatively space-saving

For example, the following figure describes

The following table shows the results of storing various string values ​​in CHAR(4) and VARCHAR(4) columns, illustrating the difference between CHAR and VARCHAR

Insert picture description here

Guess you like

Origin blog.csdn.net/XY0918ZWQ/article/details/112597369