Reputation: 110
I am usingMySQL DBMS
.I have Document table and Order table
.The relationship
between them is one to many
.
When document is created user can insert
some orders to Order table
for that document.
It takes effect to table when user clicks the register button.But after, a user can edit that document.He/She can change,update,delete orders.
When register button clicked it will effect to the Order table.When editing I want to delete all orders for that document,then insert again.But it does not seem to me good,for example,if there are 100 orders and user only changes 1 row,I have to delete 100 rows and insert 100 rows again,or if user adds new order ,I have to delete 100 rows and add 101 rows.
What is the best way to handle this situation?Note that I am using C#.Thanks in advance.
Upvotes: 0
Views: 328
Reputation: 6514
You should create a new record for the document whenever there is a change in the document. You can use a unique identifier for document and then version the document. Each order should be related to a particular version of document.
This way, you can edit the document and whenever you edit the document a new version is created and fresh orders will be for that version. The unique identifier of all the version will remain same. In short, the document will be identified by unique identifier and version.
Your suggested method has a problem, i.e. when you modify the document, you will re-insert all the orders but you will never be able to trace back the original document for which the orders were.
Upvotes: 1