Can a database table be without a primary key?

前端 未结 11 662
谎友^
谎友^ 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:24

    Like always it depends.

    Table does not have to have primary key. Much more important is to have correct indexes. On database engine depends how primary key affects indexes (i.e. creates unique index for primary key column/columns).

    However, in your case (and 99% other cases too), I would add a new auto increment unique column like temp_id and make it surrogate primary key.

    It makes much easier maintaining this table -- for example finding and removing records (i.e. duplicated records) -- and believe me -- for every table comes time to fix things :(.

提交回复
热议问题