Ask Your Question
0

Base adding a primary field

asked 2018-06-01 20:05:23 +0100

Kopfschlaeger gravatar image

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

edit retag flag offensive close merge delete

Comments

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

Jim K gravatar imageJim K ( 2018-06-01 22:07:05 +0100 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2018-06-01 20:44:37 +0100

Ratslinger gravatar image

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:

image description

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

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

edit flag offensive delete link more
1

answered 2018-06-01 22:08:08 +0100

Jim K gravatar image

updated 2018-06-01 22:09:10 +0100

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...AFTERcommand, as explained at https://stackoverflow.com/questions/6....

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

edit flag offensive delete link more

Comments

Also in Firebird it is:

ALTER TABLE tablename ALTER [COLUMN] colname POSITION <newpos>
Ratslinger gravatar imageRatslinger ( 2018-06-01 22:25:59 +0100 )edit
0

answered 2018-06-03 04:11:15 +0100

Xoristzatziki gravatar image

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).

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-06-01 20:05:23 +0100

Seen: 33 times

Last updated: Jun 03 '18