Home >Daily Programming >Mysql Knowledge >Usage of char in mysql
The CHAR data type is used to store fixed-length characters. Its features include: allocating predefined storage space regardless of data length; filling in spaces when the actual data length is insufficient; search and comparison operations are fast, but may waste storage space; Suitable for scenarios that require fixed length data, alignment or precise length guarantee.
CHAR data type
The CHAR data type is used to store fixed-length characters. Unlike the variable-length VARCHAR type, the CHAR type is allocated a predefined amount of space, regardless of how much space is actually used by the data.
Usage
The syntax is:
<code class="sql">CHAR(length)</code>
Among them, length
specifies the maximum length of the character column.
Features
Usage scenarios
CHAR type is suitable for the following scenarios:
Example
<code class="sql">CREATE TABLE customers ( name CHAR(30) NOT NULL, address CHAR(50) NOT NULL );</code>
The above example creates a table named customers
where name
and address
The columns are of type CHAR, with lengths of 30 and 50 characters respectively.
The above is the detailed content of Usage of char in mysql. For more information, please follow other related articles on the PHP Chinese website!