Page 1 of 1

Generate Numbers

Posted: Sat Aug 25, 2007 9:39 am
by fullfocus
Hello:

I hope someone can help me out.

I have a table which stores client information. In this table I also need to store a field called case_number.

My client would like the case_number to be automatically generated when she adds a new client. And, she would like the case numbers to be sequential.

So if I have ClientA in a table with case number 2020 and I add ClientB to the table, I would like their case number to be 2021. And, if I add ClientC to the table, their case number sould be 2022. Etc.

Is it possible to write a script to generate a number in sequential order and store that number into a table?

If so, how do I go about scripting something like this?

Thank you in advance.

Posted: Sat Aug 25, 2007 10:19 am
by miro_igov

Posted: Sat Aug 25, 2007 10:20 am
by smudge
Two ways to do this: query the server for the last entered number, increment, and insert the new row; or check out the auto_increment option when making tables.

Posted: Sat Aug 25, 2007 10:22 am
by miro_igov
smudge wrote: query the server for the last entered number, increment, and insert the new row;
What if in the time between the query for the highest number and the insertion another session inserts value?

Posted: Sat Aug 25, 2007 12:08 pm
by califdon
Yes, use an Auto Increment field. The database engine will insure that every case number is unique. The numbers will be assigned consecutively, based on the exact sequence the records were inserted.