D
D
Denis2020-04-18 14:43:17
PHP
Denis, 2020-04-18 14:43:17

Track changes to a specific field in the database, perhaps?

There is a table in the database, is it possible to track that a specific field has changed and only that! Let's say we have a table with fields name, phone, city. Need to track the city field. If the name or phone number changed, then no events, but if the city field changed, there is an event and it needs to be tracked? How can it be done?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bkosun, 2020-04-18
@Drumsid

Use triggers:

CREATE TRIGGER `after_update_table_name` AFTER UPDATE ON `table_name`
 FOR EACH ROW BEGIN

  IF `OLD`.`field_name` <> `NEW`.`field_name` THEN
    # Your action
  END IF;

END

https://dev.mysql.com/doc/refman/8.0/en/trigger-sy...

D
d-stream, 2020-04-18
@d-stream

use triggers

R
Rsa97, 2020-04-18
@Rsa97

Trigger to change the field and write to a separate change table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question