Re: [Phplib-users] nextid - how does it work?
Brought to you by:
nhruby,
richardarcher
From: Layne W. <la...@dr...> - 2003-07-16 22:48:39
|
> There are some instances where it is useful or even necessary to know > ahead > of time what primary key will be assigned to a given record when it is > inserted. This function provides one means of doing that. Here are some other uses for nextid() from personal experience: 1. Reference IDs based on date in the format YYYYMMxxxx (where xxxx provides for enough IDs). At the beginning of each month I can set my counter to e.g. 2003070000 and increment from there, skipping unused 200306xxxx IDs. 2. Non-primary keys. For instance, the primary key for an employee table is the SSN, but if I also want to know that I was the first employee, Fred was the second employee, etc. I need to keep another counter. 3. Force Unique IDs. MySQL's auto-increment feature creates an ID one greater than the largest ID currently in the table. If I create a new record and then delete it before another record is created, MySQL will reuse the ID. Occasionally I will duplicate table structures in two databases (one for editing, one for holding currently published data). MySQL's behavior eliminates any chance of data integrity when publishing newly edited data. I'm sure there are more reasons out there... Layne Weathers |