I have an Access database. My frontend depends on a specific record in one table.
The ID
column must have the value 1
.
But the column is of type AutoNumber
. I cannot create a record with a specific ID
.
I tried everything from removing relations, keys and changing the data type to normal number type.
But even if I then create a record of ID=1
I cannot change back the column data type to AutoNumber
.
Is this even possible somehow?
Actually that is not true. The Access Database Engine allows us to insert arbitrary values into an AutoNumber field. The following is Python, but it illustrates the point:
Edit:
Thanks to @Storax for mentioning that the Access Database Engine resets the next AutoNumber value to n + 1 if we insert n into the table. That is okay if n is greater than the largest existing AutoNumber value, but it can cause errors if we "back-fill" values like id=1 when id=2 already exists.
The easiest way to properly reset the next AutoNumber value is to open the database in MSACCESS.EXE and run a "Compact and Repair Database" operation on it.