Autoincrement based on a set of other columns

Posted by slack3r on Stack Overflow See other posts from Stack Overflow or by slack3r
Published on 2010-05-16T08:49:39Z Indexed on 2010/05/16 9:00 UTC
Read the original article Hit count: 172

Filed under:
|

I have a table Course and every Course has many Resources.

Course
==========
course_id

Resource
==========
course_id
number

I want something like a seperate 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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about db2