Sample Header Ad - 728x90

Foreign Key - from same table and parent table

1 vote
1 answer
1297 views
I have 2 tables. First table is parent **COLLECTIONS_OF_MAPS** | id | title | | -------- | -------------- | | 50013 | Geological Map Series | | 50014 | Climate Map Series | Second table is a child (but whilst describing map layers, it also has entries that are more like group layers, like parents to child maps within the same table, so there is a recursion element here) - this is then realised in a treeview control in software, just for context purposes. **MAP_LAYERS** | id | parent_layer_id | name | | -------- | -------------- |-------------- | | 1233 | 50013 | Hillshade | | 1228 | 50013 | Cultural Data | | 1231 | 50013 | Rock Types | | 1235 | 1233 | Offshore Hillshade | | 1234 | 1233 | Onshore Hillshade | | 1229 | 1228 | World Cities | | 1230 | 1228 | World Countries | | 1245 | 1228 | World Rivers | | 1270 | 1231 | Sedimentary Rock | | 1271 | 1231 | Igneous Rock | | 1272 | 1231 | Metamorphic Rock | I have just shown an example for the first map collection - "Geological Map Series". As you can see it the MAP_LAYERS parent_layer_id column references entries from BOTH tables; it's parent and itself. Can I create a foreign key rule to that references the ids of itself and or its parent table?
Asked by Vidar (157 rep)
Aug 18, 2022, 02:03 PM
Last activity: Oct 13, 2022, 12:08 PM