Auto-increment

Discuss the database features

Auto-increment

Postby Bill L » Tue Oct 02, 2018 9:23 pm

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
Bill L
 
Posts: 2
Joined: Tue Oct 02, 2018 9:16 pm

Re: Auto-increment

Postby UnklDonald418 » Wed Oct 03, 2018 4:54 pm

Always backup your database before making any changes like this.
Edit and then run the following query.
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1084
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA


Return to Base

Who is online

Users browsing this forum: No registered users and 10 guests