SQL statement

With the database open, Tools -> SQL. This opens the "Execute SQL Statement" dialog

1) To add a primary key to a table, this is the "formula" to use:

ALTER TABLE <tablename> ADD [COLUMN] <columnname> Datatype
[(columnSize[,precision])] [{DEFAULT <defaultValue> |
GENERATED BY DEFAULT AS IDENTITY (START WITH <n>[, INCREMENT BY <m>])}] |
[[NOT] NULL] [IDENTITY] [PRIMARY KEY]
[BEFORE <existingcolumn>];

Note: the table name and column name (field name) should be in double quotes. Here are some examples from simple to more complex. The table's name is Sample, and its field name is First Name.
1 ALTER TABLE "Sample" ADD COLUMN "ID" INTEGER PRIMARY KEY;
2 ALTER TABLE "Sample" ADD COLUMN "ID" INTEGER PRIMARY KEY BEFORE "First Name";
3 ALTER TABLE "Sample" ADD COLUMN "ID" INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 0);

Closed & reopen to take effect

Source: https://listarchives.libreoffice.org/global/users/msg24861.html