Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - C ++ runtime environment built on CentOS 6.6 and Oracle database connection (Database)

- Java memory area (Programming)

- Using IPFilter bridge filter in the FreeBSD system (Linux)

- Oracle table of nested loop connection (Database)

- RealVNC Server 5.2.3 Installation and Configuration In Fedora (Server)

- Lua4.0 interpreter entrance (Programming)

- 3 ways to create a lightweight, durable system of Ubuntu Linux USB disk (Linux)

- Setting CentOS firewall open port (Linux)

- Linux command binlog by filtering out the complete SQL statement (Database)

- CentOS 7.1 install NTFS-3G (Linux)

- Oracle10g 64-bit installation solution in Windows 2008 Server R2 (Database)

- How to use Aptik to backup and restore Apps/PPAs under ubuntu (Linux)

- grub boot error resolution examples (Linux)

- Linux System shutdown procedures (Linux)

- Oracle to create an external table (Database)

- Linux system boot process ARM platforms (Linux)

- Nginx introduced Dynamic Module Architecture (Server)

- Bash added to the Vi mode indicator (Linux)

- Linux Kernel 4.2 Installation Instructions (Linux)

- PostgreSQL with the C Completing the storage process instances (Database)

 
         
  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.
Suggest

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
     
         
         
         
  More:      
 
- Linux environment variable configuration and save places (Linux)
- Restrict console access to Linux servers to improve security (Linux)
- C ++ Fundamentals study notes (Programming)
- RabbitMQ tutorial examples: RabbitMQ installation under Windows (Linux)
- CentOS card fails to start at boot progress bar certmonger solve (Linux)
- VMware virtual machine to install CentOS 6.2 (Linux)
- RedHat 6 xrdp use remote login interface (Linux)
- Use read command to read user input (Programming)
- JavaScript prototype and prototype chain and project combat (Programming)
- Depth understanding of C language (Programming)
- Linux common network tools: batch scanning of nmap hosting service (Linux)
- Linux system file directory structure Introduction (Linux)
- Ubuntu 10.04 to Ubuntu 10.10 Upgrade (Linux)
- JavaScript in this usage (Programming)
- To install Jetty server configuration in detail (Server)
- Source code compiled by the installation program under Linux (Linux)
- Linux-du and df command (Linux)
- Fundamentals of the Java virtual machine memory management principles (Programming)
- Heartbeat cluster components Overview (Server)
- About Linux backdoor (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.