Are there any good reasons to have a database table without an integer primary key?

前端 未结 11 1828
感动是毒
感动是毒 2021-02-10 00:30

Although I\'m guilty of this crime, it seems to me there can\'t be any good reason for a table to not have an identity field primary key.

Pros: - whether you want to o

11条回答
  •  星月不相逢
    2021-02-10 01:16

    To be a properly normalised table, each row should only have a single identifiable key. Many tables will already have natural keys, such a unique invoice number. I agree, especially with storage being so cheap, there is little overhead in having an autonumber/identity key on all tables, but in this instance which is the real key.

    Another area where I personally don't use this approach if for reference data, where typically we have a Description and a Value

    Code, Description
    'L', 'Live'
    'O', 'Old'
    'P', 'Pending'
    

    In this situation making code a primary key ensures no duplicates, and is more human readable.

提交回复
热议问题