DEV Community

Discussion on: Design a Table to Keep Historical Changes in Database

Collapse
 
wilsonliu4 profile image
WilsonLiu

How to manage history table if I want to delete a record from the main table?
Thanks

Collapse
 
anandpowar profile image
Anand Powar

One option is to use a soft-delete i.e. set IsEnabled = false

Collapse
 
encryptblockr profile image
encryptblockr

how do we then insert records into the original table and history table at same time? do we run insert query to insert into the 2 tables at same time?

Thread Thread
 
anandpowar profile image
Anand Powar

You can run two distinctive inserts within the same transaction scope.


Begin transaction 
  Insert into original-table
  Get inserted auto-id (optional)
  Insert into history-table
Commit transaction

Enter fullscreen mode Exit fullscreen mode