What is the best practice for this scenario?
Table1: Customer
Table2: Order
CustomerId was stored in Order Table as a foreign key. What if someone accidentally renames Customer-A to Customer-X in Customer Table?
What is the best practice for this scenario?
Table1: Customer
Table2: Order
CustomerId was stored in Order Table as a foreign key. What if someone accidentally renames Customer-A to Customer-X in Customer Table?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Sep 24, 2022, 8:14 AM EDT
so what? Name can be changed but not the id, you are storing CustomerId inside order's table correct?
For DB id is the identifier not other columns.
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Sep 25, 2022, 12:30 AM EDT
As per business needs, customer name and customer id should be saved in Order table once sales order. Also provide an option to change customer name at only customer table, customer name can be changed as need but customer id will retain same, it is wrong to change customer name at order table.
Nitin SontakkeRank #264 · 9.6K reputationPosted Sep 25, 2022, 2:32 AM EDT
First nobody should be 'accidently' changing the customer table. If someone does, revert it back as soon as the error is detected.
Implement auditing if stricter control needs to be implemented, recording who changed it when (and if required, what the value before and after for each column that was modified.
If business requirement is to see all older orders with id 9 as A and after modification as X. You will need to implement a history table and a strategy that all latest names are in current table and all previous data is in history table with from date and to date columns.
Ultimately it all boils down to what business wants and how far you / IT can to go implement it considering cost and labour and time. Database THEORY suggests you should not have customer name column in Order table.
While it is absolute NO NO, nothing in world would stop you doing that though!