Re: Next Number
Posted in 1993
In article <25dnghINN7b0@emory.mathcs.emory.edu> cheryl@rrad05.army.mil ("cheryl@redriverad-emh1.army.mil") writes:
>When I create a table for use in a database, I tried to have
>a unique numeric key to that table.
>
>for instance:
...
>$ select nxt_nbr into $nxtn
>from next_n where nxt_desc = "nsn_table";
...>/* with nxtn being the next sequential number */
>$ insert into nsn values
>($nxtn, $stock, $mfg, $quantity, ...other fields)>
>then whatever you select the nxt_nbr into
>nxtn=nxtn+1 (whatever the syntax in your version, isql,4gl, esql-c)
>or
>$ update next_n set nxt_nbr to nxt_nbr + 1 where nxt_desc = "nsn_table";
The problem with this is how do you handle multiple entries at the same time?
Let's say USER A and USER B trys to add a record at the same time and the select
return the same count of nxtn to both; or, USER A press <A>dd and takes a break
before pressing the <Esc> key, and meanwhile USER B comes along and <A>dds a
record.
Why not just make the number a serial, in which case the number would be
assigned at the moment the USER presses the <Esc> key. It was also guarantee
each number would be unique.
Bob
--
---------------------------------------------------------------------------
|Bob Beaulieu Internet : bobb@netcom.com |
|EZ TRAVEL Internet : eztravel@netcom.com |
|4640-B Meridian Telephone: (408) 978-0808 |
|San Jose, CA 95124 Facsimile: (408) 978-7024 |
|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|
| Serving all your travel needs from start to finish |
| $$$ Best Fares $$$ |
| Great Service |
| Specializing in International Travel |
---------------------------------------------------------------------------