This is just a general question irrespective of database architecture.
I am maintaining an ASP.NET web application. The structure is such that,
Say on ‘Add a new employee’ webform
- The primary key (or the record id to
be saved with) is initially loaded on form
load event & displayed as a label- So when the form loads, the record id to save with is shown to the user
Positives:
- End user already knows what the id/serial of the form is (even before he saves the form)
- So on form save when he is directed
to gridview screen (with all entries)
he can search records easily
(although the most recent one is at
the top anyway)
Negatives:
- If he does not save the form, say he
just cancels after loading the data entry form,
the id/key initially fetched is
wasted (in my case it is a sequence
field fetched on form load from database)
What do you guys do in these scenarios ? Which approach would you recommend for ‘web applications’? And how to facilitate the user with a different approach ? Is our current approach recommended (To me,it wastes the ids/sequence from database)
I’d always recommend not presenting the identity field value for the record being created until the record has been created. The “create a temporary placeholder record first to obtain the identity field value ahead of time” approach can, as you mention, result in wasted IDs, unless you have a process in place to reclaim them.
You can always pop-up a message box when the user presses save that tells them the identity field value of the newly created record.