Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - Spring classic face questions Share (Programming)

- Java Concurrency - processes and threads (Programming)

- Use Android Studio and Gradle packaged multi-version APK (Programming)

- CentOS7 minimized installation can not find the 'ifconfig' command - Repair Tips (Linux)

- Python Basics Tutorial - lambda keyword (Programming)

- PHP CURL get cookies simulated login (Database)

- Installation and use GAMIT / GLOBK Software (Linux)

- ASP.NET 5 (vNext) Linux deployment (Server)

- Linux Getting Started tutorial: How to backup Linux systems (Linux)

- Detailed Linux su command to switch users Mistakes (Linux)

- iTerm - let your command line can also be colorful (Linux)

- Recovery from MySQL master data consistency summary (Database)

- How to override the plain text files and directories soft connection in linux (Linux)

- CentOS Linux firewall configuration and Close (Linux)

- Android Studio utility plug organize, create sharp artifact (Programming)

- Android engineers interview questions (Programming)

- Hadoop 1 and 2.x installation notes (Server)

- Install Gnome Flashback Classic Desktop on Ubuntu 14.10 / Mint 7 (Linux)

- Django1.5 Custom User Model (Programming)

- Linux Firewall IPCop Profile (Linux)

  Difference in MySQL VARCHAR and CHAR data format
  Add Date : 2018-11-21      
  The difference

Similar to VARCHAR CHAR type, but a different way to save and retrieve them. CHAR fixed length, while VARCHAR belong to a variable-length character type. Their maximum length and whether trailing spaces are retained, it is also different. In the storage and retrieval process does not perform case conversion.

The following table shows the various string values ​​are saved to CHAR (4) and VARCHAR (4) The results are shown after the description of the differences between CHAR and VARCHAR:

Value CHAR (4) storage requirements VARCHAR (4) storage requirements
'' '' Four-byte 'byte 1
'Ab' 'ab' 4 bytes 'ab' 3 bytes
'Abcd' 'abcd' 4 bytes 'abcd' 5 bytes
'Abcdefgh' 'abcd' 4 bytes 'abcd' 5 bytes
From the above you can see that CHAR is fixed length, regardless of the data you store is how much he would have a fixed length. While at the VARCHAR variable length but he wants to increase the total length of 1 byte, which is used to store characters in length (if the length of the statement exceeds 255, use two bytes). So the actual application user can do according to their data type.

Note that the value in the last row in the table apply only when not using strict mode; if MySQL is running in strict mode, over the length of the column value is not saved, and you receive an error.

From CHAR (4) and VARCHAR (4) columns retrieved values ​​are not always the same, because when retrieving deleted trailing spaces from CHAR columns. Explained by differences in the following example:

mysql> CREATE TABLE test (a VARCHAR (4), b CHAR (4));
mysql> INSERT INTO test VALUES ( 'ab', 'ab');
mysql> SELECT CONCAT (a, '+'), CONCAT (b, '+') FROM test;
The results are as follows:

CONCAT (a, '+') CONCAT (b, '+')
ab + ab +
From the above it can be seen, for some reason CHAR have a fixed length, than in the processing speed is much faster VARCHAR, but the relative waste of storage space, so storage is not big, but the speed requirements can use the CHAR type, Conversely VARCHAR type can be achieved.

MyISAM storage engine is recommended to use a fixed length data column instead of the variable length data columns
INNODB storage engine type recommended VARCHAR
- Linux Command Line Art (Linux)
- Common data structures and functions of Linux process scheduling (Programming)
- Some practical tips Linux (Linux)
- Using open source software to build XWiki Wiki system installed within the company (Linux)
- Android Service service applications and the phone SMS Listener Listener (Programming)
- Android Studio Personalization (Linux)
- How to generate Linux, random password encryption or decryption (Linux)
- Sort search algorithm Java - application examples with recursive dichotomy (Programming)
- Ubuntu comes with gedit editor to add Markdown preview widget (Linux)
- Specifies the open ports of the SUSE firewall settings (Linux)
- Ora-00439: feature not enabled: managed standby (Database)
- Android realize RippleEffect water (Programming)
- You need to know 12 Git High Command (Linux)
- Https (SSL / TLS) Detailed principles (Server)
- Java concurrent programming using the synchronized keyword ReentrantLock alternative primitive (Programming)
- Open SSH remote access service that allows Android phone Ubuntu 14.04 (Linux)
- Modular JavaScript (Programming)
- SSH does not require a password to log on to a Linux server (Server)
- C ++, overloading, cover, hide (Programming)
- Unity Greeter Badges: the lost session icon back to the login screen Ubuntu (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.