How can I automatically populate a newly added column that references a foreign key?

24 views Asked by At

I'm working through the PSQL guide online and came across this problem.

I have two tables, one that looks like this called properties:

properties table

and the other that looks like this called types:

types table

I would like to add a NEW column to the first bigger table. The column would be called type_id and would be a foreign key referencing the type_id in the smaller table. Is there way to automatically populate this new column since that type_id would be given based on the type value in the same properties table?

The best idea I've come up with is to just manually populate it or just create some bash script. Is there a simpler PSQL querying method that would do the trick?

0

There are 0 answers