01 February,2016 by Tom Collins
Question: I maintain a database table with 1 column. It is a lookup table for object ids. The column is called “object_id.” The values in the table are unique. Should I leave the table with 1 column and use the values as the key or should I add a column with incremental ids.?
Answer: Without being able to see the actual data , I would initially say both options can be valid in the right circumstances. But you metioned the values are unique and they are object ids. Based on that information I’d opt for using the column “object_id” as the natural key. It isn’t obvious that any extra value is added by adding a surrogate key.
Before deciding on which approach to use , review some of the arguments for and against using a natural key or surrogate key.
Natural key versus Surrogate key. A natural key is composed of an attribute already in the real world. A surrogate key is a unique identifier for an object already in the database. The main difference is that the surrogate key is not part of the application data , and would have no meaning outside of the database. For example:
Name_id Surname
Santana, Hendrix and Satriani all have meaning. 1,2,3 not associated with the Surname, are just a set of numbers.
Using a natural key has its advantages and disadvantages
Surrogate keys
If you'd like to read more on Primary keys and arguments for\against on Auto generated Primary keys read How to decide on the Primary Key - SQL Server DBA
DBA - Database Architect - Data Architect - What’s the difference ?
DBA Ignorance , complacency and arrogance experiment
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |