Michael Lackhoff wrote: > I need some pseudo-unique numbers like invoice numbers. They start every > year with 1, so autoincrement won't work. My idea was to use a helper > table with just just two fields 'year' and 'last_used_number'. Is it > enough to create a two column unique key or would it be better to do > something along these lines: > - lock table (or row?) > - read last_used_number for the year > - increment it > - save > - unlock > > Is there an idiom for this kind of task?
You can usually do this kind of ++ thing in one INSERT...SELECT statement: INSERT INTO invoice (id) SELECT MAX(id)+1 FROM invoice; - Perrin ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object