Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AutoIncrement Field and Duplicating Records
Message
 
 
To
03/08/2007 14:11:43
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01245869
Message ID:
01245871
Views:
29
>Another developer (currently on vacation) created a field (Claim) as an autoincrementing integer, to act as a primary key (the index itself is just a Regular, not Candidate). But now we are getting bad data, and the field values seemed to work okay for the first 25000 or so - and then reset to 1. So now there are are hundreds of bad records. So the last 800-odd records have duplicated claim numbers. The immediate question is, whether there is any way programmatically to determine what the next autoinc value is, and then how to reset it. The other question is how it got screwed up, and what to do to prevent it.

I would suggest to create a new table with the same structure as your bad table + OldNumber to keep the bad number.

Then try
insert into this table (fiel2, field3, OldNumber) select field2, field3,  Claim from BadTable
In other words, don't include auto-increment field into your insert, so the AutoInc field would be populated correctly now.

However, you now need to update all related tables, if this one was used in relations.

That may be a little bit tricky...

You may got bad data if you did append from file which included ClaimNumber.

You also need to set the index as Primary (or Candidate for the free table), since it is a PK. This would prevent an error in the future.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform