当前位置:网站首页>MySQL data type learning notes
MySQL data type learning notes
2022-07-01 06:35:00 【Small dollar】
There are five types of plastic surgery
int Type account 4 A byte a byte eight bits is 2 Of 32 bits
int(5) Indicates that the width is 5, But if it goes beyond 5 It doesn't matter
int(5)zerofill Time dissatisfaction 5 Bit will be used automatically 0 fill , At the same time, it becomes an unsigned number
8.0.17 When creating a table, indicate that the field is not indicating the number of words ,zerofil Indicates the width , Unsigned words are 0-4294967295
Applicable scenario
tinyint: System settings 0-100 When
smallint: The system sets the total inventory 65535 Unsigned maximum
mediumint: Passenger flow at the station 16 million
int: Big enough , It is often used, such as the product number
bigint: Large website hits
Floating point type
Floating point numbers and fixed-point numbers are used in larger scenarios than integers
float: Single precision 4
double: Double precision 8
Floating point problem unsigend The space doesn't get bigger .mysql A special case , Therefore, it is generally not increased in order to make it larger unsigend float(m,d)m Is the sum of decimal and integer digits ,d It's a decimal place , This representation is called a nonstandard type
Use doube and float When calculating data, there will be errors if a certain number is equal to a certain number , Try not to use the floating-point type = Judge whether the data are equal , that mysql Is there a precise data type ? There are fixed-point numbers
Fixed-point number
decimal(m,d) Total storage space used m+2 individual , Floating point numbers represent a wider range of values . The bottom layer uses strings to store data, so it is accurate enough
decimal If the precision and scale are not specified, the default is (10,0) There are no decimals by default , If it exceeds the specified range, it will be rounded off
mysql 8.0 The precision and index of the back will be added
If in the default decimal If you add decimals, you will be rounded off
A type of
1-64 Bit storage
Is not specified m The default is 1 position , Default 1 Bit to store a value
insert into my(f1) values(2) An error will be reported here , Because decimal 2 Is to store two digits 10,
When looking up the stored value in the command line, I found that 16 Base display , If you want to specify the hexadecimal display, then bin(F1) This shows
If you want to display in decimal select f1 +0, f2 + 0 from my
Because of the operation with the decimal system, the display result is also decimal
Explanation of date time type
year Occupy 1 The storage space of bytes is relatively small , General writing 4 There is a difference between two digits , At the same time, four digits must be enclosed in single quotation marks
date type 3 Bytes yyyy-mm-dd, You want the current system time to be now() perhaps currentdate()
The number type can also , You can also write numeric types , There are implicit transformations
time 3 Bytes Minutes and seconds hh-mm-ss Anterior band D For days
12:10 Indicates hours and minutes
values(2 12:30:29)2 God 12 Hours 30 branch 29 second
datetime Occupy 8 Bytes Specific date Minutes and seconds
Used a lot
timestap Less bytes But the storage range is limited 1970 To 2038 year
At the same time, the time zone will change , The stored is converted into milliseconds according to the time zone , The number of milliseconds will also change when the time zone changes , When sorting by month, day, hour, minute and second timestap It'll be faster
Text string type
char
char Specify a character by default , If specified 5 Can accommodate 5 Chinese characters
And when the storage quantity is 5 When , Storage 3 The two empty spaces on the right of the are automatically filled with spaces . Automatically remove the blank space when searching .
Put in ‘12 ’ When , If you calculated the length of this string, it would have been 4 But the result is 2, In fact, two spaces are automatically removed
varchar The number must be specified , A Chinese character has three bytes varchar(20)5.0 The above version refers to 20 Characters , So you can save it 20 The Chinese characters
Wise remark of an experienced person : Specifically, if you store very short messages , Like house number varchar Use char
Fixed length use uuid For storage , Use when you need to change back and forth varchar. Specifically, the storage engine is needed to connect .innodb Use varchar
text type
tinytexy:
text:
mediumtext:
longtext:
There's no fixed length , Primary keys cannot be used , The actual storage type is not too large. It is recommended to use char perhaps varchar
Enumeration type .
Provide values when creating tables , When inserting, you can only add , Case ignored . You can also use an index to call enumeration elements , such as 123, You can also join null
set type : The number of members is 64 You can choose more than one
Binary type
json type
Type of space
summary : If the integer is int type , decimal decimal, date datetime(m,d) Specify scale and precision . If the string is non negative, it is automatically defined as unsigned, Decimal type is decimal, If more than decimal The storage range of decimal and integer are stored separately , If the storage length is equal, use char, If not, use varchar, If the length exceeds 5000 Then use text Storage
边栏推荐
猜你喜欢

【#Unity Shader#自定义材质面板_第二篇】
![阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]](/img/3c/7684b7c594f7871471f89007294703.png)
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]

产品学习(二)——竞品分析

C语言课设工资管理系统(大作业)

SQL语句
![[wechat applet] view container and basic content components](/img/25/181986ab4bf048854d1d1ca87de637.jpg)
[wechat applet] view container and basic content components

On whether variables are thread safe

High order binary search tree
![[wechat applet] to solve button, input and image components](/img/7f/a61ee2f610b2f0f9fb0b34cb960f81.jpg)
[wechat applet] to solve button, input and image components

C语言课设图书信息管理系统(大作业)
随机推荐
Terminology description in the field of software engineering
Draw a directed graph based on input
Rotate the animation component around the circle, take it and use it directly
Several ways of gson's @jsonadapter annotation
Mysql 表分区创建方法
[ManageEngine Zhuohao] helps Julia college, the world's top Conservatory of music, improve terminal security
问题:OfficeException: failed to start and connect(三)
Picture server project test
【Unity Shader 描边效果_案例分享第一篇】
How does the port scanning tool help enterprises?
Summary of wechat official account embedded program to jump to wechat
脏读、幻读和不可重复读
数据库笔记
RestTemplate使用
TCL statements in SQL (transaction control statements)
软件工程复习
Interview questions for HW (OD) post
【微信小程序】视图容器和基本内容组件
伪装请求头库: anti-useragent
[ManageEngine Zhuohao] helps Huangshi Aikang hospital realize intelligent batch network equipment configuration management