开发者

Updating PK values mysql

开发者 https://www.devze.com 2023-02-13 02:45 出处:网络
I have a 2 tables that I wish to update articles and articles_entities articles has a PK of id and articles_entities has the FK article_id both these fields are char(36) currently a UUID. I am looking

I have a 2 tables that I wish to update articles and articles_entities articles has a PK of id and articles_entities has the FK article_id both these fields are char(36) currently a UUID. I am looking to convert these fields to int(10).

Is there a way I can update the 2 tables with 1 query and key the keys matching? or do I have to write a script to look through each articles and update all references?

I am using InnoDb if 开发者_Python百科that helps.


Two steps:

  1. Ensure your foreign key is set to "ON UPDATE CASCADE", then update the mother table's ID field so it contains numbers. The ON UPDATE CASCADE constraint will have InnoDB update the child table as it updates the mother... If you have a lot of rows, be prepared that this will be extremely slow.

  2. Change the type of both columns to INT. You may need to drop the foreign key before you do so and re-create it afterwards.

0

精彩评论

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