How do I use CHAR and VARCHAR differently in MySQL 5.7?
I understood the following, but is it okay to put fixed length strings in VARCHAR and all VARCHAR?
The differences between varchar and char in mysql 5.7 are as follows:
https://dev.mysql.com/doc/refman/5.7/en/char.html
training spaces are removed from CHAR columns upon retrieval.
As you can see, there are the following differences:
create table example(avarchar(10), bchar(10));
insert into example values ('A', 'B');
insert into example values ('A', 'B');
insert into example values ('A', 'B');
select a, length(a), b, length(b) from example;
+------------------------------------------------------------------------------------------------
| a | length(a) | b | length(b) |
+------------+-----------+------------+-----------+
| A | 1 | B | 1 |
| A | 10 | B | 10 |
| A | 10 | B | 1 |
+------------+-----------+------------+-----------+
Char is fine if you want to handle fixed-length data that is not a trailing blank, but if you have enough capacity to include length information in varchar, it is almost the same.
Personally speaking, except for fixed-length data from outside (such as general-purpose machines), I think I usually use varchar (oracle varchar2).
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
581 PHP ssh2_scp_send fails to send files as intended
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.