Question

I want to have a column on a table that is automatically updated when the row is updated, this column is a soundex version of another column, hypothetically, something like this:

CREATE TABLE `test` (`title` VARCHAR(255), `title_soundex` VARCHAR(255) DEFAULT SOUNDEX(`title`) ON UPDATE SOUNDEX(`title`));

Something like this is even possible? Is there any other approaches to make this happen solely on mysql without updating the code that uses this table ?

Was it helpful?

Solution

Yes, it is possible, but not using constraints.

You would need to create an on update trigger on the test table that would check if the title has been updated, and if so, update the title_soundex field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top