I have a table Course and every Course has many Resources.
Course
==========
course_id
Resource
==========
course_id
number
I want something like a separate autoincrement for each course_id. Or, in other words, I want to auto-enumerate the resources for a given course. For example, the resource table could look something like:
course_id | number
==================
1 | 1
1 | 2
2 | 1
1 | 3
1 | 4
2 | 2
2 | 3
and so on.
I want to do this in SQL, using IBM DB2.
You should let
Resourcepick its own ids……and discover the rank via queries:
This is undoubtedly more work for the optimiser, but will simplify life dramatically in every other respect (e.g., handling deletions).