In the logical model, a table must have at least one key. There is no reason to arbitarily specify that one of the keys is 'primary'; all keys are equal. Although the concept of 'primary key' can be traced back to Ted Codd's early work, the mistake was picked up early on has long been corrected in relational theory.
Sadly, PRIMARY KEY
found it's way into SQL and we've had to live with it ever since. SQL tables can have duplicate rows and, if you consider the resultset of a SELECT
query to also be a table, then SQL tables can have duplciate rows too. Relational theorists dislike SQL a lot. However, just because SQL lets you do all kinds of wacky non-relational things, that doesn't mean that you have to actually do them. Is is good practise to ensure that every SQL table has at least one key.
In SQL, using PRIMARY KEY
on its own has implications e.g. NOT NULL
, UNIQUE
, the table's default reference for foreign keys. In SQL Server, using PRIMARY KEY
on its own has implications e.g. the table's clustered index. However, in all these cases, the implicit behaviour can be made explicit using specific syntax.
You can use UNIQUE
(constraint rather than index) and NOT NULL
in combination to enforce keys in SQL. Therefore, no, a primary key (or even PRIMARY KEY
) is not necessary in SQL Server.