将table1.column(主键)数据复制到具有外键约束的table2.column。 [英] Copy table1.column (primary key) data to table2.column with foreign key constraint.

查看:77
本文介绍了将table1.column(主键)数据复制到具有外键约束的table2.column。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要将table1的SHORT_NAME列(带主键约束)复制到table2的SHORT_NAME列(带有外键约束)。< br $>


TABLE1.SHORT_NAME(主键)

TABLE2.Short_NAME(外键 - 对Table1.SHORT_NAME的引用)



我尝试了什么:



更新指标设置SHORT_NAME =(从WBCOUNTRIES选择SHORT_NAME指示人员。 SHORT_NAME = WBCOUNTRIES.SHORT_NAME);



留言

Hi,

I need to copy a column SHORT_NAME(with primary key constraint) of table1 to a column SHORT_NAME(with foreign key constraint) of table2.

TABLE1.SHORT_NAME (primary key)
TABLE2.Short_NAME (Foreign Key - reference to Table1.SHORT_NAME)

What I have tried:

UPDATE INDICATORS SET SHORT_NAME = (SELECT SHORT_NAME FROM WBCOUNTRIES WHERE INDICATORS.SHORT_NAME=WBCOUNTRIES.SHORT_NAME);

Message

149 rows updated.





但是没有数据更新。



But no data is updated.

推荐答案

你的JOIN条件是说只更新已经存在的记录。您需要更改此选项以获取不在子表中的那些(具有外键的那些),为此您需要不同的JOIN条件
your JOIN condition is saying to update only already existing records. You need to change this to fetch those which are not in child table( one with foreign key), for this you need different JOIN condition


这篇关于将table1.column(主键)数据复制到具有外键约束的table2.column。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆