How to change the order of columns in table?

Hello,
In MS Access it’s quite easily to change the order o columns.
Surprisingly LibreOffice doesn’t provide such basic functionnality.
Does exist some work-around ?
Thanks

Hello,

Changing the order of fields in a database is not a function of Base but rather that of the database. This is difficult to accomplish in the HSQLDB embedded DB but easy in Firebird embedded.

In HSQLDB embedded (default v1.8), it may be best to define a new table with the wanted structure then copy and paste the data from the old table into the new table taking care to match the fields correctly.

For Firebird embedded (default v3.0 with Experimental features enabled) you can use SQL:

Syntax: ALTER TABLE tablename ALTER [COLUMN] colname POSITION

Example: ALTER TABLE salary_history2 ALTER old_salary POSITION 2

From Firebird documentation:
The POSITION keyword changes the position of an existing column in the notional “left-to-right” layout of the record.
Numbering of column positions starts at 1.
• If a position less than 1 is specified, an error message will be returned
• If a position number is greater than the number of columns in the table, its new position will be adjusted silently to match the number of columns.

Other databases may differ. You have not stated which database you are using. Base itself is not a database but rather a front end to a database.

Usually, tables are an “unrelevant” storage medium for record fields. By “unrelevant”, I mean you don’t process records relying on some implicit convention provided by the DB engine. Your fields are accessed through SQL statements which specify which fields will be used for retrieval, then you’ll copy the “important” fields to variables or other records. The exact structure of the record, the order of fields does not really matter from a logical point of view.

When it comes to resource optimisation, this order may matter depending on alignment constraint in the DB engine. These constraints are not the same in every engine. So, a recipe for one is not valid for another. Unless you have specific needs, such as a very small embedded device, don’t consider this. The most important is getting your application working as expected (remember that “early optimisation is the root of all evil”). However, as a general tule of thumb, list the longest fixed-sized fields first. (…)

(continued)
If you have a single “blob”, list it last. Anyway, read the recommendations shipping with the engine.

(a note for this site maintainers: strange, I thought the 200-chars limit for comments had been recently relaxed)

@ajlittoz My comment here allows for 1000 characters.

@Ratslinger: I posted yesterday comments larger than 200 chars, but I was caught here at this outdated limit. That’s why I wrote “strange”. Sometimes machines, including computers, are really nasty :wink:

Hello,
The suggestion of Jan doesn’t work:
link text

@Pavel_47 Please note there is no Jan here. Jan is a month.

From the image provided, you are executing the ALTER statement in an incorrect area. You cannot do this under the Query section as this is mainly for Select statements (there are some exceptions to this). Rather, this is done from the main Base menu item Tools->SQL...

Thank you Ratslinger. I’m sorry for “Jan”.
I’ve tried this command in the location you suggested.
Also doesn’t work. Here is screenshot:
link text

Have re-tried this multiple times on Mint18.3 with LO v6.1.4.2 without problems. Possibly a LO Windows version problem. Best to file Bug report.

Works !!! Although table_name and column_name must be enclosed in quotation marks

Quotation marks are only necessary depending upon case used and database itself.

In my case without quotes SQL command fails