For example, a schedule is stored in the database, which can be replenished.

Can the program know that something has changed in the database (for example, something has been added to some table), so that it can do some kind of action?

If so, how is it done by what means and how much is it resource-intensive for the database?

If the Entity Framework has some kind of convenient mechanism, then I would like to consider how this is done using the Entity Framework without it.

And I would like with examples. For example, some abstract database with two tables.

  • one
  • @Zufir, I think it will do. - iluxa1810
  • @ Zufir, And this thing will not heavily load SQLServer? - iluxa1810
  • Did not notice. But I have these tables change well, sooooo rarely :) - Zufir

1 answer 1

Usually, the task “check that something was added” hangs a request for checking MAX (id) and compares the old value with the new one.

If you want to check that something has changed, create a updated_at field for each entry in the database, put an index on it (for performance), check the necessary tables every n-time using the SELECT MAX (updated_at) FROM table query, and if different from the old - do your actions. You can conveniently, for example, show which entries have changed, simply by taking all entries where updated_at is greater than a specific value.

The updated_at field can also be used, as is the case with id, if it is not necessary to split whether a new entry is added or edited. Simply fill it in when adding a record, and not just when updating.

This request will work very quickly due to the device operation of the indices, but if there are many such requests, then it is probably better to somehow give it through an API that would cache the results for a while.

In general, this is the simplest and most appropriate architectural solution , some people create a TRIGGER to update the tables, and if the table is updated, write the date of the last update to another table and compare it with the previous one, someone checks the checksum of the table or the table file.