[Solved] Auto increment

Discuss the database features
Post Reply
rmj156248
Posts: 3
Joined: Sun Aug 09, 2015 1:14 am

[Solved] Auto increment

Post by rmj156248 »

I was using the base application in OO and the auto increment feature worked once and I saved the database I created shut down and left. I came back to add more data to it and found the data base was deleted, so I recreated it and the field that it uses for a primary key is ID and it work before on auto increment no it does not work at all even when I delete the field and add it back an manualy set it to auto increment and click save open office sets it back to no instead of yes for auto increment. the database was just for inventory. if some one could tell me how to fix so I don't have to keep putting in the next number in line.

I also uninstalled and reinstalled it nothing else has worked.

thanks.
Last edited by rmj156248 on Tue Aug 11, 2015 6:10 pm, edited 2 times in total.
open office 4.1.1 on windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Auto increment

Post by Villeroy »

menu:Tools>SQL...

Code: Select all

ALTER TABLE "Your Table Name" ALTER COLUMN "ID" SET GENERATED BY DEFAULT AS IDENTITY;
menu:View>Refresh Tables
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
rmj156248
Posts: 3
Joined: Sun Aug 09, 2015 1:14 am

Re: Auto increment

Post by rmj156248 »

got unexpected token
Unexpected token: GENERATED in statement [ALTER TABLE "Products"ALTER COLUMN "ID" SET GENERATED]
open office 4.1.1 on windows 7
FJCC
Moderator
Posts: 9278
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Auto increment

Post by FJCC »

Does this work?

Code: Select all

ALTER TABLE "YourTableName" ALTER COLUMN "ID" INTEGER  GENERATED BY DEFAULT AS IDENTITY;
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
rmj156248
Posts: 3
Joined: Sun Aug 09, 2015 1:14 am

Re: Auto increment

Post by rmj156248 »

yes it worked but will I have to keep doing it every time I have a new database
open office 4.1.1 on windows 7
FJCC
Moderator
Posts: 9278
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Auto increment

Post by FJCC »

If you define the table initially to have an auto incrementing primary key, that setting should be permanent. I don't know why that wasn't working on your database.

When you close down the database, be sure to wait a few seconds before turning off the computer. Base files are complex and you should give the system time to finish all of the tasks.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Scarsax2018
Posts: 12
Joined: Wed Jul 24, 2019 8:52 am

Re: [Solved] Auto increment

Post by Scarsax2018 »

I have imported a calc spreadsheet into Base and the ID prime key does not increment, tried the SQL command but I get "2: Primary key not allowed in statement [ALTER TABLE "Membership" ALTER COLUMN "ID" INTEGER GENERATED BY DEFAULT AS IDENTITY]" as status.
OpenOffice 4.1.6 Mac Os 10.11.6
Scarsax2018
Posts: 12
Joined: Wed Jul 24, 2019 8:52 am

Re: [Solved] Auto increment

Post by Scarsax2018 »

Solved it by making a new DB and importing Calc data.
OpenOffice 4.1.6 Mac Os 10.11.6
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: [Solved] Auto increment

Post by UnklDonald418 »

Scarsax2018, the command

Code: Select all

ALTER TABLE "Membership" ALTER COLUMN "ID" INTEGER GENERATED BY DEFAULT AS IDENTITY
will only work on an empty table. If the table already has data in it you need to prime the number generator.

Code: Select all

ALTER TABLE "Membership" ALTER COLUMN "ID" INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH  XX)
where XX = 1 + the largest ID value currently in the table.
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
Scarsax2018
Posts: 12
Joined: Wed Jul 24, 2019 8:52 am

Re: [Solved] Auto increment

Post by Scarsax2018 »

Thanks for your reply.
OpenOffice 4.1.6 Mac Os 10.11.6
Post Reply