Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - The lambda expression Java8 (constructor references) (Programming)

- Java Concurrency: synchronized (Programming)

- Objective-C basic program structure (Programming)

- CentOS / Linux install VNC Server (Linux)

- DRBD switchover (Server)

- Database start listening TNS-12537, TNS-12560 error (Database)

- Setting the RedHat9 Intrusion Detection System (Linux)

- Management and application Oracle external table (Database)

- Linux kernel update error, update-initramfs: failed Solution (Linux)

- MySQL view (Database)

- The method to mount the CD under Linux (Linux)

- Du and df show disk space usage inconsistent Causes and Treatment (Linux)

- GAMIT 10.50 installed in Ubuntu 12.04 system (Linux)

- QEMU image file used: qcow2 and raw (Linux)

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

- Teach you self-built Linux firewall free (Linux)

- Install Firefox 28 on Ubuntu, Linux Mint (Linux)

- Linux operating system ARP Spoofing Defense (Linux)

- Oracle 11g to create a second instance on Linux (Database)

- Improve the Ubuntu SSH login authentication approach speed (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.
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:      
 
- Detailed Linux network security policies and protection measures (Linux)
- PostgreSQL with the C Completing the storage process instances (Database)
- linux remote control software (Linux)
- MySQL5.6.17 compiler installation under CentOS (Database)
- Applications Linux leap second problem caused (Linux)
- Linux memory management -free learning experience (Linux)
- Php and MySQL command add to the environment variable method in Linux system (Linux)
- How to set IonCube Loaders in Ubuntu (Linux)
- Simple RPM package production (Linux)
- How comprehensive resist attacks from the network (Linux)
- Examples of Python any parameters (Programming)
- Linux system ARP attack solution (Linux)
- MySQL Tutorial: Building MySQL Cluster under Linux (Database)
- Getting Started with Linux system to learn: how to install USB webcams come in raspberry (Linux)
- WebLogic 12c Configuration Node Manager Managed Server (Database)
- jQuery plugin dynamic label generation (Linux)
- CentOS 6.4 installation and configuration LNMP build PHP server runtime environment (Server)
- Git Tutorial Comments (Linux)
- PHP 7.0 Upgrade Notes (Linux)
- Try the command ip, ifconfig is obsolete under Linux (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.