Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
JavaScript
149 rows updated.


But no data is updated.
Posted
Updated 17-Nov-16 23:10pm
Comments
Richard Deeming 17-Nov-16 14:03pm    
Because you've told it to set the SHORT_NAME to exactly the same value.

What were you expecting to happen?

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900