Should each and every table have a primary key?

后端 未结 15 1021
甜味超标
甜味超标 2020-11-22 07:00

I\'m creating a database table and I don\'t have a logical primary key assigned to it. So, I\'m thinking about leaving it without a primary key, but I\'m feeling a bit guilt

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 07:42

    It is a good practice to have a PK on every table, but it's not a MUST. Most probably you will need a unique index, and/or a clustered index (which is PK or not) depending on your need.

    Check out the Primary Keys and Clustered Indexes sections on Books Online (for SQL Server)

    "PRIMARY KEY constraints identify the column or set of columns that have values that uniquely identify a row in a table. No two rows in a table can have the same primary key value. You cannot enter NULL for any column in a primary key. We recommend using a small, integer column as a primary key. Each table should have a primary key. A column or combination of columns that qualify as a primary key value is referred to as a candidate key."

    But then check this out also: http://www.aisintl.com/case/primary_and_foreign_key.html

提交回复
热议问题