当前位置:网站首页>Mysql database Basics: introduction to data types
Mysql database Basics: introduction to data types
2022-06-29 16:04:00 【Long lasting bangbangjun】
mysql Database foundation
1、 integer
classification
| Integer types | byte | Range |
|---|---|---|
| Tinyint | 1 | A signed :-128~ 127, Unsigned :0~255 |
| Smallint | 2 | A signed :-32768~32767, Unsigned |
| Mediumint | 3 | A signed :-8388608~ 8388607 |
| Int/integer | 4 | A signed :-2147483648 ~ 2147483647 |
| Bigint | 8 | A signed :-9223372036854775808 ~ 9223372036854775807, Unsigned :0~ 9223372036854775807*2+1 |
characteristic
1、 How to set up unsigned and signed
create table Table name (
t1 INT, # Set signed ( Default )
t2 INT UNSIGNED # Set up unsigned
# If you add a negative number , The result will be displayed as 0
)
2、 If the inserted data exceeds the value range of the integer , Will be submitted to the out of range abnormal , And insert the critical value .
3、 If the length is not set , There will be a default length
2、 decimal
2.1 classification
floating-point
| Floating point type | byte | Range |
|---|---|---|
| float(M,D) | 4 | ±1.75494351E^ 38~±3.402823466EE^38 |
| double(M,D) | 8 | It's big ~~~ |
Fixed point type
| Fixed point number type | byte | Range |
|---|---|---|
| DEC(M,D),DECIMAL(M,D) | M+2 | The maximum value range is related to double identical , Given decimal The valid value range of is determined by M and d decision |
2.2 characteristic
(1)M and D The meaning of
M: Integer part digit + Number of decimal places
D: The number of decimal places reserved ( rounding )
(2)M and D All can be omitted
(3) If the time is decimal Fixed point type , be M The default is 10,D The default is 0
If it is float and double type , The precision is determined by the precision of the inserted value
(4) The accuracy of fixed-point type is higher , If the precision of the inserted value is required to be high , For example, the fixed-point type is considered for currency operation .
3、 Character
3.1 Shorter text
| String type | The maximum number of characters | Description and storage requirements | difference |
|---|---|---|---|
| char(M) | M | M by 0~255 Integer between | Fixed length characters , It's more space consuming , High efficiency |
| varchar(M) | M | M by 0~65535 Integer between | Variable length characters , Not that space consuming , Low efficiency |
3.2 Longer text
| String type | Description and storage requirements |
|---|---|
| text | Store long text types |
| blob | Store picture type |
4、 Date type
4.1 classification
| The date type | Number of bytes | minimum value | Maximum |
|---|---|---|---|
| date | 4 | 100-1-01 | 9999-12-31 |
| time | 3 | -838:59:59 | 838:59:59 |
| year | 1 | 1901 | 2155 |
| datetime | 8 | 1000-01-01 00:00:00 | 9999-12-31 23:59:59 |
| timestamp | 4 | 1970 | 2038 Some time in the year |
Add :
datetime and timestamp The difference between
(1)timestamp The time range supported is small ,datetime The value range of is relatively large
(2)timestamp Related to the actual time zone , Better reflect the actual date , and datetime It can only reflect the local time zone at the time of insertion
(3)timestamp Attribute Collection of mysql Version and sqlMode The impact of
5、 Enumeration type (Enum)
The value to be inserted must belong to one of the values specified in the list .
for example :
# Build table , Define data of an enumeration type
create table tab_char(
c1 ENUM('a','b','c')
);
# Insert value
insert into tob_char values('a'),('b'),('c');
# If you insert an unexpected value in the list , May be an error
insert into tob_char values('m'); # Report errors
6、set( type )
set Used to hold collections
and Enum Similar type , It can hold 0~64 Members .
and Enum The biggest difference in type is :set Type can select more than one member at a time , and Enum Only one... Can be chosen . According to the number of members , The bytes occupied by storage are also different 
- for example
create table tab_set(
s1 SET('a','b','c','d')
)
insert into tab_set values('a');
insert into tab_set values('a,b');
insert into tab_set values('a,b,c');
result 
边栏推荐
- Summary of recent work
- 攻防演练之战前扫雷:漏洞管理的5大措施
- wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)
- A. Marathon
- Kotlin annotation declaration and use
- The way of enterprise transformation and upgrading: digital transformation, thinking first
- Kotlin annotation Statement and use
- Motion capture system for apple picking robot
- STM32与GD32笔记
- It is expected to significantly improve the computational performance of integrated photonic circuits. The Tsinghua team proposed a diffraction pattern neural network framework
猜你喜欢

面试官:说一下MySQL事务隔离级别?

Huawei cloud AOM version 2.0 release

Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能

路由汇总带来的三层环路-解决实验

Volcano engine was selected into the first "panorama of edge computing industry" in China

Detailed explanation of list set

动作捕捉系统用于苹果采摘机器人

时间格式化 GTM转北京时间

攻防演练之战前扫雷:漏洞管理的5大措施

Autodesk Revit 2023软件安装包下载及安装教程
随机推荐
蓝桥杯2015年CA省赛(填坑中)
Polarimetric SAR surface classification
three.js和高德地图结合引入obj格式模型-效果演示
kotlin 注解声明与使用
C#学习二:堆和栈
2022 OpenVINO DevCon 大揭秘!英特尔携众多合作伙伴深化开发者生态建设,释放AI产业创新潜能
Introduction to radar related contents
Science:大脑中睡眠的相互关联原因和结果
three. JS and Gaode map are combined to introduce obj format model - effect demonstration
kotlin 注解聲明與使用
2022-06-29日报: 李飞飞划重点的「具身智能」,走到哪一步了?
A. Marathon
【crossbeam系列】5 crossbeam-util和crossbeam-queue:一些实用的小东西
Kotlin annotation declaration and use
关于 麒麟系统启动应用报错“undefined symbol: __cxa_throw_bad_array_new_length, version Qt_5“ 的解决方法
R语言plotly可视化:plotly可视化箱图、可视化多个分类变量的箱图(Several Box Plots)
【Try to Hack】XML
El table column row button anti weight control loading
Leetcode-234-palindrome linked list
按键精灵打怪学习-窗口绑定保护技能和点击技能