When storing external data, I usually have two ids. One is external and one is internal. I inevitably need to keep indexes on both ids for lookups. Examples:
- Storing stripe customers, products, ids
- Storing shopify products, images, variants, etc.
- Any external data really
QUESTIONS:
Is this just a necessary part of storing external data or can I be using the external ids only?
Which ids should I use as relational keys between my tables internally?
- External ids
- Internal ids
- Both internal and external ids
In terms of column naming, is it common to have:
id
andexternal_id
internal_id
andexternal_id
; orid
andshopify_product_id
-
2This question is similar to: Surrogate key vs Natural key. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.mustaccio– mustaccio2024年07月05日 21:53:49 +00:00Commented Jul 5, 2024 at 21:53
-
This calls for opinions, but my opinion is that you need no extra artificial "internal" key as long as you always have a unique, immutable "external" key.Laurenz Albe– Laurenz Albe2024年07月08日 07:35:39 +00:00Commented Jul 8, 2024 at 7:35
1 Answer 1
Having written many applications with such databases, I would always use your internal id within the database. There are several reasons (not all will apply to you)
- The
internal id
is smaller and usually numeric, whereas you need to store theexternal id
as a string. - The
external id
can change, when the store decides on a different supplier. Theinternal id
needs to remain the same. - Some stores deal with multiple suppliers, each having their own
external id
s.
For naming, call them whatever feels natural to you.