Base adding a primary field

How does one add a primary field to an existing table? Will the new field atomatically increase the first entry by 1?

What engine? For example MySQL, or the default embedded HSQLDB 1.8.

Hello,

A primary key is a unique piece of information. Typically it is a field of type Integer using auto increment. Whether the field is at the beginning, middle or end of the table makes no difference. To ADD a primary key, right ckick on a table name & select Edit. In a blank line at end of fields give it a field name such as ID. In Field Type use the dropdown & select Integer [Int]. Under the field names, in Properties, set AutoValue to Yes. You can then right click on box left of the field name and select Primary Key and a symbol of a key will appear in that box. Save the table. Sample:

For more info on this and all of Base, see the documentation → Documentation/Publications

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

As @Ratslinger wrote, theoretically, there should be no need to move it to the top.

However, if perhaps for aesthetic reasons you want it at the top, some engines such as MySQL make it possible to change column order with an ALTER TABLE...AFTER command, as explained at sql - How to move columns in a MySQL table? - Stack Overflow.

Such commands can be entered in Base by going to Tools → SQL.

Also in Firebird it is:

ALTER TABLE tablename ALTER [COLUMN] colname POSITION <newpos>

What you can do (ex. mytbl) with most DBs:

  1. Rename the table. (oldmytbl)
  2. Save odb
  3. Copy oldmytbl and paste as mytbl
  4. Save odb

LibreOffice will ask if you want a primary key (or you can enter a new field at the top and use as primary key).