# 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

edit retag close merge delete

Sort by » oldest newest most voted

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 <newpos>

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.

more

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

( 2019-01-11 19:39:47 +0100 )edit

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

( 2019-01-11 19:41:47 +0100 )edit

@ajlittoz My comment here allows for 1000 characters.

( 2019-01-11 19:46:38 +0100 )edit

@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 ;-)

( 2019-01-11 20:21:32 +0100 )edit