Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Go bottom
Message
From
16/10/2004 12:02:12
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
15/10/2004 16:12:54
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00950231
Message ID:
00951946
Views:
11
>Mohammed
>
>You got answers that will work but you are not asking the right question.
>
>Don't use MAX() to get the next number. It is better to generate next number.

Now since it's a Saturday and I have some time on my hands, here goes the general list of good and valid reasons for this:

- max() will give the next number based on what's already in the table. If two users request the max before either of them writes, they'll get the same number. And that will cause duplicate keys (which may be handy if you lock your keys in the car, but not so nice in a database situation).

- max() will not see any deleted or filtered-out records. If the last record is deleted (the last user just found out that record with the key 16 is bad, and decided to delete it and start over), max() will not see it and will produce 15 again. Also, if any of Set Filter To, Set Order To {index with a FOR clause} or Set Key To is in effect, it will calculate the max() from visible records only.

Therefore, an independent counter is the solution, Q.E.D.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform