当前位置:网站首页>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 
边栏推荐
- Timecho of Tianmou technology completed Angel round financing of nearly RMB 100 million and built the original time series database of the industrial Internet of things around Apache iotdb
- 华为云AOM 2.0版本发布
- 为Golang项目编写Makefile
- 微博评论高可用高性能计算架构
- 事件相关电位ERP的皮层溯源分析
- 89. (cesium article) cesium aggregation diagram (custom picture)
- A. Beat The Odds
- How to add a search box to your WordPress site
- [data analysis] five common questions about learning SQL?
- 硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件
猜你喜欢

支付宝“安全锁”入选信通院“护童计划”优秀案例:超过33万用户已开通游戏保护

架构实战营模块五作业

华为云AOM 2.0版本发布

2022年第一季度保险服务数字化跟踪分析

关于 麒麟系统启动应用报错“undefined symbol: __cxa_throw_bad_array_new_length, version Qt_5“ 的解决方法

C # learning 1: value type and reference type

Stlink troubleshooting

PostgreSQL source code learning (23) -- transaction log ④ - log assembly

cmake学习-2

基于JSP实现毕业设计选题系统
随机推荐
事件相关电位ERP的皮层溯源分析
How to create a login page in WordPress
The role of each layer in convolutional neural network
R语言plotly可视化:plotly可视化箱图、可视化多个分类变量的箱图(Several Box Plots)
Where has lifeifei reached in his key "embodied intelligence"?
MySQL XA distributed transaction
华为云AOM 2.0版本发布
Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)
What are the advantages of intelligent chat robots? Senior independent station sellers tell you!
硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件
从第三次技术革命看企业应用三大开发趋势
【大家的项目】 Rbatis ORM官网上线
Business Intelligence BI and business management decision-making thinking No. 3: business quality analysis
LeetCode-64-最小路径和
C language big job - Matching System
Introduction to radar related contents
The way of enterprise transformation and upgrading: digital transformation, thinking first
mysql数据库基础:DDL数据定义语言
STM32与GD32笔记