Note/大学笔记/数据库导论/笔记/数据库笔记03——数据类型——2022-03-10.md

105 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 数据类型
### 一、数值类型
整形 int(3) ,3表示最多显示的数字个数
浮点型 float(5,1)共有五位有效数字小数点后一位double(5,1)、
定点型decimal(5,1),精度
```mysql
create table tmpl(
x float(5,1),
y double(5,1),
z decimal(5,1)
);
```
### 二、日期时间类型
#### 1year一个字节范围1901-2155
1.四位串或四位数字都可以表示year
2.以两位或一位串表示year'0'-69表示2000-2069年'70'-'99'表示1970-1999年
3.以两位(或一位)数字表示串:**0表示0000**1-69表示2001-2069年70-99表示1970-1999年
#### 2time三个字节范围-838:59:59~+838:59:59
1.HH:MM:SS
2.D HH:MM:SS(D的范围是0-34)
有冒号时:从左向右解释
无冒号时:从右向左解释
按照 天 小时 分钟 秒
3.插入当前时间
```mysql
insert into 表名 values (current_time);
//now 获取日期和时间
insert into 表名 values (now());
```
#### 3date三个字节
1.'YYYY-MM-DD'
2.'YY-MM-DD'
3.YYYYMMDD或者YYMMDD 注意:不能加分隔符
4.当前日期current_date 和now()
#### 4datetime:八个字节
1.'YYYY-MM-DD HH:MM:SS'或者'YYYYMMDDHHMMSS'字符串
2.'YY-MM-DD HH:MM:SS'或者'YYMMDDHHMMSS'字符串
3.YYYYMMDDHHMMSS或者YYMMDDHHMMSS字符串
4.当前日期和时间 now()
#### 5timestamp在 datetime 下增加时区(东八区中国)
```mysql
set time_zone='+10:00';
```
### 三、字符串类型
1.char 和 varchar
char 固定长度字符串,当检索时,尾部的空格会被删除掉
varchar 长度可变的字符串,当检索时,尾部的空格会保留
char(4)内存固定分配四个字节
varchar(4),根据存储内容变化最大为4
2.text:文章内容,评论
3.enum
4.set自动删除重复的
### 四、二进制类型