1

i have one table called product

product_id    rate      Quantity    modified_fields
    1          100         4
    3          32          2
    5          43          1 

so if i am updating any field in product table

suppose i am changing rate 100 to 50 then i need to set up one trigger that will update modified_fields column with rate:50(New value)

 product_id       rate      Quantity    modified_fields
        1          50          4         rate:50
        3          32          2
        5          43          1 

Edit: What I basically need is that I need to identify which particular column was edited on an Update operation. Table can have 50 columns, and any one of them can be updated. Trigger will basically determine which column is updated, and the corresponding new value. It will then update the modified fields column with the update column name : new value

Any help would be appreciated

Ketan G
  • 507
  • 1
  • 5
  • 21
  • You need query for trigger ? – Rahul Jan 10 '17 at 10:58
  • provide query then – Ketan G Jan 10 '17 at 10:59
  • you can directly write simple query as UPDATE product set rate = 50, modified_fields = CONCAT('rate',':',50) for same table, if it will be other table then trigger fine, but for same table you could use this – Rahul Jan 10 '17 at 11:03
  • @VforVendettaWhat I basically need is that I need to identify which particular column was edited on an Update operation. Table can have 50 columns, and any one of them can be updated. Trigger will basically determine which column is updated, and the corresponding new value. It will then update the modified fields column with the update column name : new value – Ketan G Jan 10 '17 at 12:15

1 Answers1

1

You can get the reference of link1 and link2.

Alternatively, you can try like this,

UPDATE product set rate = 50, modified_fields = CONCAT('rate',':',50);

If it is for same table. Trigger should be used in case of updating columns of another table.

Community
  • 1
  • 1
Rahul
  • 18,271
  • 7
  • 41
  • 60