Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - Ubuntu 10.10 install Oracle 10g Installation Guide (Database)

- Java, hashcode, equals and == (Programming)

- Android custom controls create the simplest skid menu in the history (Programming)

- xCAT error Unable to dispatch hierarchical sub-command to NORESOLUTION: 3001 (Linux)

- Calculate CPU utilization (Linux)

- TOAST function in PostgreSQL (Database)

- Ubuntu 14.04 after the restart the default maximum screen brightness solutions (Linux)

- FPM quickly create packages with RPM (Linux)

- JavaScript: understanding regular expressions (Programming)

- Dual system Linux (Ubuntu) into the Windows NTFS partition's mount error (Linux)

- Oracle partition table data migration, process management automation (Database)

- JavaScript, some conclusions about the implicit conversion (Programming)

- Awk include binding capacity larger than the specified size of all files directory (Linux)

- CentOS 6.5 opens the Xmanager Remote Desktop login (Linux)

- CentOS source installation GitLab Chinese Version (Server)

- Android SDK Manager can not update the domestic solutions (Linux)

- MongoDB study notes - polymerization (Database)

- BusyBox build root file system (Linux)

- extundelete: the Linux-based open source data recovery tools (Linux)

- Increase ssh security service under Linux (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
- The direct insertion sort algorithm (Programming)
- Changes in C # asynchronous programming model (Programming)
- Examples of safety testing system notes for RedHat Linux (Linux)
- Unity Greeter Badges: the lost session icon back to the login screen Ubuntu (Linux)
- Whisker Menu 1.4.3 Install menu Linux (Linux)
- A well-known but rarely used skills: object pool (Programming)
- How to configure SNMPv3 on Ubuntu, CentOS and Cisco systems (Linux)
- Relationship between Linux permissions with the command (Linux)
- linux smartd [FAILED] appears at startup (Linux)
- Linux system security knowledge (Linux)
- The difference between free command displays the buffers and cache (Linux)
- Linux (CentOS) SSH login without password authentication (Linux)
- Adjust the size of the hard disk VirtualBox (Linux)
- JavaScript notes --Objects (Programming)
- Python: Finding meet the conditions specified in the file directory (Programming)
- Use Docker / LXC quickly launch a desktop system (Linux)
- Snapshot DataGuard (Database)
- Zabbix Agent for Linux Installation and Configuration (Server)
- C ++ Replication Control: Assignment operators and destructors (Programming)
- Spring Data JPA call a stored procedure examples (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.