Hi.
Suppose I have a table like
table components(
 componentType int,
 description varchar(200),
 serialNo int;
)

I want to give each component a different id. I could make the serialNo
of type autoInc, and that could be acomplished automaticaly. However,
that's not exactly what I want. I want that serial to be incremental FOR
EACH componentType. For each value of componentType, the serial starts
at 0. So I could have:
0,'comp 1',0
0,'comp 2',1
0,'comp 3',3
1,'comp 4',0
1,'comp 5',1
2,'comp 6',0
and so on ...

What is the best to acomplish this ?
I can only see a way out:
Use an interceptor with a preInsert method that does a select on the
used serials for a certain componentType and adds 1 to the last value
found.
However it doesn't seem a very elegant solution. And I think it could
lead to racing problems if 2 users try to add componentes at the same
time.
Could this be acomplished through a different database modeling?
Database constraints ?
Stored procedures ?
I'm using mysql, but would be willing to change to another opensource db
if really needed.

Any ideas ?

Regards,
Carlos. Anjos.


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
DbForms Mailing List

http://www.wap-force.net/dbforms

Reply via email to