Should I add an external id for every table?
For example if I have these tables :
Customer
=======================================
Id Name Gender
---------------------------------------
1 John M
2 Doe M
---------------------------------------
CustomerPurchase
==========================================================================
Id ExternalId CustomerId TotalQty
--------------------------------------------------------------------------
1 PO0313-0001 1 10
--------------------------------------------------------------------------
In that example, I understand that ExternalId is required in CustomerPurchase table (for printing, etc).
But I don't see any reason why Customer table should need one as well.
FYI, the reason I asked this because a friend of mine said that SAP uses ExternalIds in their tables.
Should I use ExternalId in every table?
Am I missing any ExternalId's other usage besides for user's eye friendlier identification?
Thanks!
Best Answer
In layman's words:
Use surrogate primary keys as primary keys when:
If a natural key exists that doesn't fall into the conditions listed above, for the sake of God, use it, especially if the key is an ISO standard or is issued by some respected institution, like country codes, airport or airline IATA codes, MAC addresses, car plaque numbers, IMDB movie codes, radio station call signs, etc. That would allow you to interoperate easier.
Above conditions mean surrogate keys will have to be used in many tables. But not all.