Can a database table be without a primary key?

前端 未结 11 558
谎友^
谎友^ 2021-01-31 14:39

Can anyone tell me if a table in a relational database (such as MySQL / SQL SERVER) can be without a primary key?

For example, I could have table day_temperature

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 15:32

    Even if you do not add a primary key to an InnoDB table in MySQL, MySQL adds a hidden clustered index to that table. If you do not define a primary key, MySQL locates the first UNIQUE index where all the key columns are NOT NULL and InnoDB uses it as the clustered index.

    If the table has no primary key or suitable UNIQUE index, InnoDB internally generates a clustered index GEN_CLUST_INDEX on a synthetic column containing row ID values.

    https://dev.mysql.com/doc/refman/8.0/en/innodb-index-types.html

提交回复
热议问题