I'm trying to create a database that tracks electrical cables. Each cable contains 1 or more cores that are connected to terminals at each end. The number of cores in each cable is defined in a table.
| number_of_cores | cable_id
|----------2-------|---1-----|
The core table is as follows
cable_no | from_id | core_mark | to_id
1001 | 1 | 1 Black | 2
1001 | 2 | 1 White | 4
I want to create a check that will prevent another 1001 cable core from being inserted.
Is this possible in postgresql?
Ideally, if I tried to insert another 1001 cable with another unique core number, the error would be something like "all cores used on cable 1001"
Thanks,