当前位置:网站首页>MySQL基础 数据类型精讲
MySQL基础 数据类型精讲
2022-06-09 08:50:00 【Maximize+】

数值类型

日期时间类型

字符串类型
纯文本类型

空间类型

常见属性

可以不为负数
字符集设置
#关于属性:character set name
SHOW VARIABLES LIKE 'character_%';
#创建数据库时指定字符集
CREATE DATABASE IF NOT EXISTS dbtest12 CHARACTER SET 'utf8';
SHOW CREATE DATABASE dbtest12;
#创建表的时候指定表的字符集
CREATE TABLE temp(
id INT
) CHARACTER SET 'utf8';
SHOW CREATE TABLE temp;
#创建表指明字段时,可以指定字段的字符集
CREATE TABLE temp1(
id INT,
NAME VARCHAR(15)CHARACTER SET 'gbk'
);
SHOW CREATE TABLE temp1;
整数类型







#整数数据类型
USE dbtest12;
CREATE TABLE test_int1(
f1 TINYINT,
f2 SMALLINT,
f3 MEDIUMINT,
f4 INTEGER,
f5 BIGINT
);
DESC test_int1;
INSERT INTO test_int1(f1)
VALUES(12),(-128),(127);
SELECT *FROM test_int1;
#超出了范围
#Out of range value for column 'f1' at row 1
INSERT INTO test_int1(f1)
VALUES(128);
CREATE TABLE test_int2(
f1 INT,
f2 INT(5),
f3 INT(5) ZEROFILL #显示宽度为5,当insert的值不足5位时,用0填充。
#当使用ZEROFILL时会自动添加 unsigned 无符号的意思
)
INSERT INTO test_int2(f1,f2)
VALUES(123,123),(123456,123456)
SELECT*FROM test_int2;
INSERT INTO test_int2(f3)
VALUES(123),(123456);
SHOW CREATE TABLE test_int2;
CREATE TABLE test_int3(
f1 INT UNSIGNED#不包括负数
);
INSERT INTO test_int3
VALUES(2412321);
#Out of range value for column 'f1' at row 1
INSERT INTO test_Int3
VALUES(4294967296);
浮点类型








#浮点类型
CREATE TABLE test_double1(
f1 FLOAT,
f2 FLOAT(5,2),
f3 DOUBLE,
f4 DOUBLE(5,2)
);
DESC test_double1;
INSERT INTO test_double1(f1,f2)
VALUES(123.45,123.45);
SELECT*FROM test_double1;
INSERT INTO test_double1(f3,f4)
VALUES(123.45,123.456);
SELECT*FROM test_double1;#存在四舍五入
#整数位出错
INSERT INTO test_double1(f3,f4)
VALUES(123.45,1234.456);
INSERT INTO test_double1(f3,f4)
VALUES(123.45,999.995);
#测试float和double的精度问题
CREATE TABLE test_double2(
f1 DOUBLE
);
INSERT INTO test_double2
VALUES(0.47),(0.44),(0.19);
SELECT SUM(f1)
FROM test_double2;
SELECT SUM(f1) = 1.1,1.1=1.1
FROM test_double2;
定点数类型




#定点数类型
CREATE TABLE test_decimal1(
f1 DECIMAL,
f2 DECIMAL(5,2)
);
DESC test_decimal1;
INSERT INTO test_decimal1(f1)
VALUES(123),(123.45);
SELECT*FROM test_decimal1;
INSERT INTO test_decimal1(f2)
VALUES(999.99);
SELECT*FROM test_decimal1;
INSERT INTO test_decimal1(f2)
VALUES(67.567);#存在四舍五入
#Out of range value for column 'f2' at row 1
INSERT INTO test_decimal1(f2)
VALUES(1267.567);
#情况相同
INSERT INTO test_decimal1(f2)
VALUES(999.995);
ALTER TABLE test_double2
MODIFY f1 DECIMAL(5,2);
DESC test_double2;
SELECT*FROM test_double2;
DELETE FROM test_double2;
INSERT INTO test_double2
VALUES(0.47),(0.44),(0.19);
SELECT SUM(f1)
FROM test_double2;
位类型

#位类型
CREATE TABLE test_bit1(
f1 BIT,
f2 BIT(5),
#f3 bit(65)
f3 BIT(64)
);
DESC test_bit1;
INSERT INTO test_bit1(f1)
VALUES(0),(1);
SELECT *FROM test_bit1;
INSERT INTO test_bit1(f2)
VALUES(31);
边栏推荐
- Configuring the environment for RMAN backups_ Configure advanced backup options
- Mock interview plan; Campus simulated interview plan; Job search simulation interview contest plan; Planning book of simulated job hunting competition of School of economics and management; College st
- 选择器误区
- 剖析虚幻渲染体系(15)- XR专题
- 2022-2028 global natural volcanic ash industry research and trend analysis report
- English grammar_ adverb
- MySQL基础 数据库创建基础
- 根据投影坐标裁剪影像中的目标区域(附有完整代码)
- MySQL基础 DML与DDL学习
- 安科瑞配电室综合监控系统实现配电室内环境的在线监测,保障配电室设备的安全运行
猜你喜欢

MySQL基础 子查询

Hvv蓝队指北

RMAN backup concept_ About RMAN incremental backup

Residual current relay uses residual current transformer to detect residual current and prevent electrical fire
![[texstudio] [3] relatively complete paper typesetting template and bib file reference method](/img/ba/160b236aaf0fc905609b8a70c7677d.jpg)
[texstudio] [3] relatively complete paper typesetting template and bib file reference method

清洗数据---2022/06/08

Remote prepayment management system helps property management solve the problem of difficult charging and statistics

环境变量Path误删除

如何解决mouseup事件失效的问题

C语言指针
随机推荐
MySQL在存储过程中使用while批量插入数据(批量提交和单个提交的性能差异)
AtCoder Beginner Contest 252
Precautions for Tencent cloud pagoda website construction
[texstudio] [3] relatively complete paper typesetting template and bib file reference method
Acwing game 54
Configuring the environment for RMAN backups_ Configure backup optimization
MySQL基础 基础认知
3D programming mode: dependent isolation mode
RMAN backup concept_ Consistent and inconsistent RMAN backups
Configuring the environment for RMAN backups_ Configure channel
成本节省 50%,9人团队使用函数计算开发 wolai 在线文档应用
[program life] internet job division; Internet development process; Division of responsibilities
Document sorting (expansion)
虚拟机安装及配置
I met a big man!
AtCoder Beginner Contest 252
安科瑞配电室综合监控系统实现配电室内环境的在线监测,保障配电室设备的安全运行
根据投影坐标裁剪影像中的目标区域(附有完整代码)
Creation of JS class and use of constructor constructor
MySQL common commands