CodeWithMosh--mysql 学习笔记(4) -- 相关数据类型

在这里插入图片描述

string types 字符串类型

char()     针对固定长度  
varchar()  针对变长   -- 用户名、密码  usually varchar(50) 地址之类-- varchar(255)
MediumBlob	最大长度 16777215 个字节(2^24-1)  16MB 16*1024*1024
LongText	最大长度4294967295个字节 (2^32-1)  4GB 4*1024*1024*1024

在这里插入图片描述
在这里插入图片描述

numeric types 数值类型

integer types 整数类型

在这里插入图片描述

Fixed-point and floating-point types 定点数类型和浮点数类型

在这里插入图片描述

decimal()   小数型 ;精确值-- 小数点后有固定位数的数字,比如货币值, 
替代词: decnumericfixed
用于科学计算   ; 近似值
float   4b
double  8b

boolean types 布尔类型

在这里插入图片描述

enum and set types 枚举和集合类型 – 限定字符串选择范围 – 少用,可以单独建立一个查询表解决需求

enum('small','medium','large')
set()

date and time types

在这里插入图片描述

常使用时间戳timestamp 4b 记录某行插入或最近更新的时间

Bolb types

在这里插入图片描述

Json types

JSON(JavaScript Object Notation) 是一种通过网络存储和传输数据的轻量级 数据交换格式。易于人阅读和编写。同时也易于机器解析和生成

语法

Json 使用 {} 定义 对象

{
	-- key为字符串
	"key":value,	
}

在products 表中添加一列为 properties 格式为 json
在这里插入图片描述

update products
set properties = '{
	"dimensions" : [1,2,3],
	"weight":10,
	"manufacturer":{"name":"sony"}
}'
where product_id = 1

update products
set properties = '{
	"dimensions" : [1,2,3],
	"weight":10,
	"manufacturer":{"name":"sony"}
}'
where product_id = 1
select product_id,
	json_extract(properties,'$.weight') as weight
--  json_extract(json_obj,path)
--  $ 表示当前json文档 ;(.)访问单独的属性或键
from products
where product_id = 1
select product_id,
	properties -> '$.weight' as weight,
	properties -> '$.dimensions' as dimensions,
	properties -> '$.manufacturer' as manufacturer,
	properties -> '$.manufacturer.name' as name,
	-- '->>' 克服字符串输出的引号
	properties ->> '$.manufacturer.name' as name_no
from products
where product_id = 1;

select product_id from products
where properties ->> '$.manufacturer.name' = 'sony'
update products
set properties = json_set( -- 更新或添加新属性
	properties,
	'$.weight',20,
	'$.age',10 -- 新增属性
)
where product_id = 1;
update products
set properties = json_remove(
	properties,'$.age'
)
where product_id = 1;

传送门

Sql Server之数据类型详解
SQL 数据类型
MySQL中tinytext、text、mediumtext和longtext等各个类型详解
SQL:BLOB 和 TEXT
JSON 语法

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值