Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to DELETE records from the Database?

I was told that we never delete records from the table, because it will be needed in future. and can I know is there any alternative than DELETE where I can DEACTIVATE the row than completely removing the row from table?

like image 845
Sharpmind Avatar asked Dec 01 '25 16:12

Sharpmind


1 Answers

You can add a bit column to your tables - call it something like IsActive or IsDeleted

When you INSERT data make sure that the data is marked with the correct value:

New record - IsActive = true
           - IsDeleted = false

Then when you what to make the records unavailable you will do an UPDATE to flag the records the opposite way:

Update - IsActive = false
       - IsDeleted = true

When you run your queries you will filter the data out according to this flag. We implement this type of soft delete throughout our system and it works to hide records.

like image 149
Taryn Avatar answered Dec 03 '25 06:12

Taryn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!