Page 1 of 1

Auto-increment

Posted: Tue Oct 02, 2018 9:23 pm
by Bill L
I am not sure what I didd but my auto increment value went from a four digit number(i.e. 1574) to a 5 digit number(11575) Now I get an integrity constraints violation SYS_FK_67 What did I do and how can i fix it

Re: Auto-increment

Posted: Wed Oct 03, 2018 4:54 pm
by UnklDonald418
Always backup your database before making any changes like this.
Edit and then run the following query.

Code: Select all

SELECT "KeyFieldName" FROM "YourTableName" ORDER BY "KeyFieldName" DESC;
The first value returned is the maximum value for the auto-increment field. Add one to that value then edit and execute the following at Tools>SQL

Code: Select all

ALTER TABLE "TableName" ALTER COLUMN "KeyFieldName" INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH <n>);