Anand
Anand

Reputation: 1021

How can I retrieve which columns were updated in a MySQL table

I have one table with 30 fields(columns). I would like to get what fields were updated within 5 minutes.

Upvotes: 0

Views: 145

Answers (2)

Naveen Kumar
Naveen Kumar

Reputation: 4601

You can write a trigger and check which columns were updated using

  FOR EACH ROW BEGIN

SET @Cols = 'Updated Columns: ';

IF OLD.col1 <> NEW.col1 THEN
 @Cols = CONCAT(@Cols, 'col1, ');
END IF;

IF OLD.col2 <> NEW.col2 THEN
 @Cols = CONCAT(@Cols, 'col2, ');
END IF;



END

@cols will contain all the updated fields

Upvotes: 0

Miqdad Ali
Miqdad Ali

Reputation: 6147

You have to log the update details to another table and run a trigger while updating your table

Upvotes: 2

Related Questions