Home >Database >Mysql Tutorial >How to store fixed length string and variable length string in the same MySQL table?
We know that CHAR is used to store fixed-length strings, and VARCHAR is used to store variable-length strings. Therefore, we can store both fixed-length and variable-length strings in the same table by declaring one column as CHAR and other columns as VARCHAR.
mysql> Create Table Employees(FirstName CHAR(10), LastName VARCHAR(10)); Query OK, 0 rows affected (0.64 sec) mysql> Desc Employees; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | FirstName | char(10) | YES | | NULL | | | LastName | varchar(10) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 2 rows in set (0.03 sec)
The above is the detailed content of How to store fixed length string and variable length string in the same MySQL table?. For more information, please follow other related articles on the PHP Chinese website!