Regardless of the DBMS? This is problem. The two most common methods are auto-incrementing columns and sequences, and most DBMSs are one or the other, but not both. Thus, a database-independent way is to have another table with one column with one value that you lock, select, update and unlock.
Usually I say “to hell with DBMS independence” and do this with sequences in PostgreSQL or auto-increment columns in MySQL. For my purposes, supporting both is better than trying to find one way that works everywhere.
source
share