Mysql中rowid作用是什么_mysql中的_rowid

前言

在Oracle数据库的表中的每一行数据都有一个唯一的标识符,称为rowid,在Oracle内部通常就是使用它来访问数据的。

而在MySQL中也有一个类似的隐藏列_rowid来标记唯一的标识。但是需要注意_rowid并不是一个真实存在的列,其本质是一个非空唯一列的别名。

PS:本文是基于MySQL 5.7进行研究的

_rowid到底是什么

在前文提到了_rowid并不是一个真实存在的列,其本质是一个非空唯一列的别名。为什么会这么说呢?

因为在某些情况下_rowid是不存在的,其只存在于以下情况:

当表中存在一个数字类型的单列主键时,_rowid其实就是指的是这个主键列

当表中不存在主键但存在一个数字类型的非空唯一列时,_rowid其实就是指的是对应非空唯一列。

需要注意以下情况是不存在_rowid的

主键列或者非空唯一列的类型不是数字类型

主键是联合主键

唯一列不是非空的。

详情可以参考MySQL官方文档内容:

If a table has a PRIMARY KEY or UNIQUE NOT NULL index that consists of a single column that has an integer type, you can use _rowid to refer to the indexed column in SELECT statements, as follows:

_rowid refers to the PRIMARY KEY column if there is a PRIMARY KEY consisting of a single integer column. If there is a PRIMARY KEY but it does not consist of a single integer column, _rowid cannot be used.

Otherwise, _rowid refers to the column in the first UNIQUE NOT NULL index if that index consists of a single integer column. If the first UNIQUE NOT NULL index does not consist of a single integer column, _rowid cannot be used.

参考资料

13.1.14 CREATE INDEX Syntax

Re: Oracle ROWID equivalent in MySQL

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值