Home > Database > Mysql Tutorial > How to store fixed length string and variable length string in the same MySQL table?

How to store fixed length string and variable length string in the same MySQL table?

PHPz
Release: 2023-09-05 22:09:16
forward
1451 people have browsed it

如何在同一个 MySQL 表中存储固定长度字符串和可变长度字符串?

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.

Example

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template