简体   繁体   English

如何在mysql的另一个表中编辑唯一的列引用作为外键?

[英]How do I edit a unique column reference as foreign key in another table in mysql?

I have one master table having column keywords varchar(120) as Unique and it is reference to another table **cmp_keywords** as a foreign key.我有一个master表,其中列keywords varchar(120)作为 Unique 并且它引用另一个表**cmp_keywords**作为外键。 Now how can I edit the column keywords value from master table and cmp_keywords table?现在如何编辑master表和cmp_keywords表中的列keywords值?

Define your foreign key with the option ON UPDATE CASCADE .使用选项ON UPDATE CASCADE定义外键。 Then just update the master table (correct term is parent table), then your child table will be updated automatically.然后只需更新主表(正确的术语是父表),然后您的子表将自动更新。

From the top of my head从我的头顶

ALTER TABLE cmp_keywords DROP FOREIGN KEY <foreign_key_name>, 
ADD FOREIGN KEY my_new_fk_name (cmp_keywords_column) ON UPDATE CASCADE REFERENCES master_table(keywords);

should do it.应该这样做。 If not, figure out the correct syntax with this link .如果没有,请使用此链接找出正确的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL 如何使用外键标识另一个表中的列? - MySQL How do I use a foreign key to identify a column in another table? 如何从外键列上的 mysql 表中删除唯一约束 - How to drop unique constraint from mysql table on a foreign key column 如何将主键放入另一个表的外键中? PHP,MySQL - How Do I Grab And Put Primary Key Into Foreign Key In Another Table? PHP, MySQL 如何将一个表的主键值插入另一个表的外键列? - How do I insert primary key value from one table to foreign key column in another? 如何获取PHP中外键引用的列名 - How do I get the column name of a foreign key reference in PHP 如何将主键作为外键插入另一个表? - How do I insert the primary key to another table as foreign key? 我无法在mysql中编辑另一个表具有外键的表 - I can't edit table that another table has a foreign key of it in mysql MYSQL仅当另一个表中不存在两列的唯一键对时,才如何更新表? - MYSQL How do I update a table only if a unique key pair of two columns does not exist in another table? 如何在MySQL的另一个表中仅选择没有相应外键的行? - How do I select only rows that don't have a corresponding foreign key in another table in MySQL? MYSQL 根据另一列创建唯一ID(这是一个外键) - MYSQL create unique id according to another column (which is a foreign key)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM