I need to create strings for each item included in the database. For example:
x00001 The first item for the sencond item x00003 for the third item x00002
The way I decided to do this is the number of rows. Before inserting the third item, I count against the database, I know that there are already 2 rows, so the next encoding is finished with 3. But there is a problem. If I delete the second item, the forward object will not be x00004, but x00003.
I can add additional columns to the table to store the next encoding, I do not know if there are other better solutions?
What do you want SELECT MAX (id)
or SELECT Max inside the transaction (some_function (id))
.
As stated in Oded's answer, there are many ways in which the database has its own way of providing sequence and non-numeric ID based on DBMS.
In addition, you can create broken columns in the form of different columns and 00001 and both columns form the primary key; Most of the database sequences will be able to provide.
However, whether or not your primary key should be on this question; Y
suggests that the key has some meaning (otherwise you will be content with a plain integer ID).
Comments
Post a Comment