Maybe this is a stupid question, but I'm kind of stuck here... So I have a table A
state | city
MI Detroit
...
And I have a state table B
state_id | state
1 MI
...
And a city table C
city_id | city | state_id
1 Detroit NULL
I want to add a foreign key column in city table, I've already created a foreign key column in it with the syntax ALTER TABLE city ADD CONSTRAINT city_state FOREIGN KEY (state_id) REFERENCES state(state_id); But the foreign key column was filled with null since it doesn't know the relation between city table and the state table.
How can I fill in the foreign key column with right state id? Can someone help?
newly created foreign key column? A foreign key is a constraint on what data you can store, it doesn't create any new columns or data. Also, your tags are conflicting (mysql & postgresql).ALTER TABLEsyntax the state_id column is only filled with NULL