Edit: currently I will keep question opened. to get an very rough answer.
Shortly, Here's a schema
Asked this question because From this topic https://www.sisense.com/blog/when-and-how-to-use-surrogate-keys/
Combining Natural and Surrogate Keys Certain business scenarios might require keeping the natural key intact as a means for users to interact with the database. In these cases …
If a natural key is recommended, use a surrogate key field as the primary key, and a natural key as a foreign key. While users may interact with the natural key, the database can still have surrogate keys outside of the users’ view, with no interruption to user experience.
If a natural key must be used without an additional surrogate key, be sure to combine it with a surrogate key element. In our financial database example, Expense Reports (ER-123) have a natural key is used in conjunction with a surrogate sequential key. This format prevents many of the natural key side effects listed above.
I really found that maybe solve my problem. As am afraid from surrogate key. But XPO and ORM providers support Surrogate key by (100%). unlike Composite Key. Which described in many articles as a bad in new databases design. Surrogate Key vs Natural Key for EF Surrogate vs. natural/business keys
And many articles about that. This is not case here. Am speak about combine or use both surrogate key and also add natural key (as indexes or unique indexes only not PK) Now back to schema above and topic above that speak about combine both. I have a Branch which have surrogate key Oid, all tables have Oid as surrogate key. Also I have natural key for example (BranchID),
- Branch Table have (Oid[surrogate], BranchID[Natural Key - Unique Index not PK]
- InvTransHed have (Oid[Surrogate], itd_brn, itd_type, ith_num) as Natural Key (Unique Index I mean)
- InvTransDet have (Oid[Surrogate], itd_brm, itd_typ, itd_num, itd_lne as Natural Key [Unique Indexs])
What I actually make is linking all Surrogate keys Oid with its Foreign Key side. for example: Branch.Oid Linked with InvTransHed.BranchSKey [Skey = surrogate key]
Why I need to combine Surrgoate Key with Natural Key(as Unique Indexes)?
- Easy create reporting with JOINs (Branch with InvTransDet directly without moving to InvTransHed).
- Readability for technical support. easy to make any join without care about surrogate key. or Linking to parent tables till reach what we need.
- Easy to understand and ORM Providers (friendly by 100% for sure)
Here's a questions that blown my head:
- Should I linking Surrogate Keys only with their another side Foreign Key. Or I must link also Natural Indexes to their Natural Keys. Branch.BranchID => InvTransHed.ith_brn?
- About naming opposite side FK. Branch.Oid surrogate linking with InvTransHed.BranchSkey. Is naming important here to be same for readability?
- Guide me please for that (Title = Question).