mysql - 我可以创建一个没有 PK 的 InnoDB 表吗?如果是的话,是否会使用二级索引作为聚集索引?

标签 mysql primary-key innodb clustered-index database-indexes

是否可以创建没有主键的 InnoDB 表?

由于 InnoDB 表的结构是围绕 PK 的聚集索引,那么没有 PK 的表的结构会是什么?该表仍然是聚集索引,但围绕辅助键吗?

谢谢。

最佳答案

http://www.sqlinfo.net/mysqldocs/v50/storage-engines.html#innodb-table-and-index

14.2.13。 InnoDB 表和索引结构

If you do not define a PRIMARY KEY for your table, MySQL picks the first UNIQUE index that has only NOT NULL columns as the primary key and InnoDB uses it as the clustered index. If there is no such index in the table, InnoDB internally generates a clustered index where the rows are ordered by the row ID that InnoDB assigns to the rows in such a table. The row ID is a 6-byte field that increases monotonically as new rows are inserted. Thus, the rows ordered by the row ID are physically in insertion order.

关于mysql - 我可以创建一个没有 PK 的 InnoDB 表吗?如果是的话,是否会使用二级索引作为聚集索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5494565/

相关文章:

MySQL EXISTS() 错误

php - 选择时将不存在的字段设置为值

php - 在我的实时应用程序上获取看起来很像 session 冲突的行为。不知道为什么

mysql - SQL 左连接。花费太长时间。

mysql - 在 Azure 数据库中为 MySQL 创建 MyISAM 表是否启用?

php - 使用 PHP for 循环的 SQL 更新时间太长

java - 使用 MySQL 查询结果设置 DatePicker 值

php - MySQL:更新一行并删除原始行以防它成为重复行

具有 innodb 和可序列化事务的 Mysql 不会(总是)锁定行

mysql - 如何使用两个索引对 MySQL 表进行分区