Skip to content
Advertisement

Is a Primary Key necessary in SQL Server?

This may be a pretty naive and stupid question, but I’m going to ask it anyway

I have a table with several fields, none of which are unique, and a primary key, which obviously is.

This table is accessed via the non-unique fields regularly, but no user SP or process access data via the primary key. Is the primary key necessary then? Is it used behind the scenes? Will removing it affect performance Positively or Negatively?

Advertisement

Answer

Necessary? No. Used behind the scenes? Well, it’s saved to disk and kept in the row cache, etc. Removing will slightly increase your performance (use a watch with millisecond precision to notice).

But … the next time someone needs to create references to this table, they will curse you. If they are brave, they will add a PK (and wait for a long time for the DB to create the column). If they are not brave or dumb, they will start creating references using the business key (i.e. the data columns) which will cause a maintenance nightmare.

Conclusion: Since the cost of having a PK (even if it’s not used ATM) is so small, let it be.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement