Auto-increment

Discuss the database features
Post Reply
Bill L
Posts: 2
Joined: Tue Oct 02, 2018 9:16 pm

Auto-increment

Post 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
LibreOffice 5.3 on windows 10
UnklDonald418
Volunteer
Posts: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Auto-increment

Post 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>);
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply