How to implement what MS calls "Autonumber" key field?

Creating tables and queries
Post Reply
JSSchiavo
Posts: 1
Joined: Tue Feb 06, 2018 2:16 am

How to implement what MS calls "Autonumber" key field?

Post by JSSchiavo »

FOrgive me if this is addressed here somewhere, but I didn't find it.

I'm steeped in the MS "way", and now, converting to OpenOffice, I want to define a table with a primary key that is incremented automatically with each record added: what MS calls "Autonumber".

I need to create a database for folder files, with an integer file number ("ID") that is simply applied by the system.

I haven't found anything similar as yet. Can you direct me?

Many thanks for the help.

Stephen
OpenOffice 4.1.4 on Windows 10
User avatar
robleyd
Moderator
Posts: 5082
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: How to implement what MS calls "Autonumber" key field?

Post by robleyd »

The term used by Base may be either autoincrement or autovalue - see the offline help and search primary keys
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
UnklDonald418
Volunteer
Posts: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to implement what MS calls "Autonumber" key field?

Post by UnklDonald418 »

One way is to use an SQL command to alter your table.
If your table already has an "ID" integer field as the Primary Key and there are no records in the table then edit the table name and if your table already contains records with previously assigned values for "ID" then you need to replace the 0 with a new start value. Then go to Tools->SQL and execute

Code: Select all

ALTER TABLE "YourTableName" ALTER COLUMN "ID" INTEGER GENERATED BY DEFAULT AS IDENTITY (start with 0);
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
Nocton
Volunteer
Posts: 533
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: How to implement what MS calls "Autonumber" key field?

Post by Nocton »

In your table, select Field Type 'Integer' and then in the Field Properties select 'AutoValue = 'Yes'.
OpenOffice 4.1.12 on Windows 10
rwzelnick
Posts: 4
Joined: Wed Oct 19, 2011 5:18 pm

Re: How to implement what MS calls "Autonumber" key field?

Post by rwzelnick »

>>> In your table, select Field Type 'Integer' and then in the Field Properties select 'AutoValue = 'Yes'.
i tried that several times with an empty database but after I save the table and go back to Edit it, Autoumber is set OFF, and is grayed out so there's no way to change it. I had to use the SQL statement ALTER... given elsewhere in this thread. I had to put data in the table, then look at the bottom index number in it, and then put that number
+ 1 in that SQL statement, as they show. It worked.
Open Office 4.0 on Win 7
Nocton
Volunteer
Posts: 533
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: How to implement what MS calls "Autonumber" key field?

Post by Nocton »

I think you must be using a 'split' database. In that case you have to use a SQL statement or copy the table to a normal, temporary, 'embedded' database, edit it as required, and then copy it back to your database.
OpenOffice 4.1.12 on Windows 10
Post Reply