开发者

Mysql on update and default

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 SOUN开发者_StackOverflow中文版DEX(`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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜