当前位置:网站首页>Mysql database implementation setting field length

Mysql database implementation setting field length

2022-06-10 17:15:00 1024 Q

Catalog

mysql Set the field length

1. About char and varchar

2. About the length of numeric types

mysql Field length understanding

int type

varchar type

mysql Set the field length 1. About char and varchar

char Is a fixed length character ,varchar Is a variable length character .

stay mysql4.0 Before the release ,char and varchar The following length represents bytes , stay utf-8 Coding format : Three bytes store a Chinese character ( Including the symbols under Chinese characters ), A byte stores an English letter , A number .

stay mysql5.0 After the version ,char and varchar The following length represents one character , A Chinese character 、 English letter 、 Numbers or symbols , It's all one character .

2. About the length of numeric types

The length of a number type does not mean that , It's more complicated .

int type : Set value range of length 1~255( Set up 0 Automatically switch to 11, Automatically change to the default when not set 11), This setting is actually the setting width , The so-called width is when the numerical value is displayed , When the width of the value is shorter than the width of the setting , The left padding will be performed automatically 0. However, to see the effect, you need to add zerofill This value , To express with 0 fill , Otherwise, no effect will be seen . We usually do not add this value when creating a database .

No matter how much width we set , Will not affect the scope of storage .int The storage range is -2147483648~2147483647( namely -2 Of 31 Power ~ 2 Of 31 Power -1).

tinyint The field value range of any length value within this range is -128~127(-2 The seventh power of -1 ~ 2 The seventh power of -1).

mysql Field length understanding

Knowledge with notes

When designing data sheets , Whether through table design or sql Statement design , Will involve the design of field length , The field length is the value in parentheses after the data type , Such as int(10),varchar(10), Field length has different meanings under different data types , Here only MySQL Medium int as well as varchar Type , Please learn the rest by yourself .

int type

int The length of the type only indicates the display width , No impact on actual storage , Such as int(10) and int(11) The data of all accounts for 4 Bytes , Only the difference of data display effect

varchar type

varchar The length of the type is the character length ( English characters ), It is also the display width , Such as varchar(3) It can only be stored at most 3 Characters , Show 3 Character length ,varchar(3) The space occupied by inserting a character in the type field and varchar(10) Type data takes the same space to insert a character .

The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .


原网站

版权声明
本文为[1024 Q]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101554537377.html