开发者

Mysql on update and default

开发者 https://www.devze.com 2023-02-05 02:35 出处:网络
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:

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

精彩评论

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