I have a table of tasks,
id | name
----+-------------
1 | brush teeth
2 | do laundry
and a table of states.
taskid | state
--------+-------------
1 | completed
2 | uncompleted
There is a bijective correspondence between the tables, i.e.
each row in the task
table corresponds to exactly one row in the state
table.
Another way of implementing this would be to place a state
row in the task
table.
id | name | state
----+-------------+-------------
1 | brush teeth | completed
2 | do laundry | uncompleted
The main reason why I have selected to use two tables instead of this one, is because updating the state
will then cause a change in the task id
.
I have other tables referencing the task(id)
column, and do not want to have to update all those other tables too when altering a task's state.
I have two questions about this.
- Is it good practice to have two tables in bijective row-row correspondence?
- Is there a way I can ensure a constraint that there is exactly one row in the
state
table corresponding to each row in thetask
table?
The system I am using is postgresql
.