Tables with no Primary Key

后端 未结 7 1665
一个人的身影
一个人的身影 2020-12-13 00:17

I have several tables whose only unique data is a uniqueidentifier (a Guid) column. Because guids are non-sequential (and they\'re client-side generated so I can\'t use news

7条回答
  •  感情败类
    2020-12-13 00:41

    The primary key serves three purposes:

    • indicates that the column(s) should be unique
    • indicates that the column(s) should be non-null
    • document the intent that this is the unique identifier of the row

    The first two can be specified in lots of ways, as you have already done.

    The third reason is good:

    • for humans, so they can easily see your intent
    • for the computer, so a program that might compare or otherwise process your table can query the database for the table's primary key.

    A primary key doesn't have to be an auto-incrementing number field, so I would say that it's a good idea to specify your guid column as the primary key.

提交回复
热议问题