Generate number using identity

3

Is it possible to generate a number before writing the record to the database? Use field identity of SQL Server 2014. Work with Delphi Berlin.

    
asked by anonymous 23.08.2017 / 16:19

1 answer

4

In general, not, at least not by% of normal%.

You can use some techniques to help with this. One is to generate the insert to get the number and then update with the actual data. But it is very problematic to do this, you have to make the application remove when you do not need it anymore, you can create holes in the numbering, you have to turn off restrictions, anyway, I do not recommend it.

Another is to have a table where you control numbering on your own and will reserve or drop the reservation if the insertion does not take effect. It's not simple, but it's a better solution.

Of course you can pick up the number after insertion, which is the most common technique and usually works well in most situations. Every idea of IDENTITY is that same, having a centralized control of the database itself.

Another way is to use a UUID / GUID as the primary key, so you do not need to generate anything in the database, you already know in advance which identifier always needs to go to the database.

It should interest you:

23.08.2017 / 16:32