| View previous topic :: View next topic |
| Author |
Message |
hwtan OOo Advocate


Joined: 24 Aug 2004 Posts: 320 Location: Singapore
|
Posted: Sun Mar 30, 2008 11:57 pm Post subject: [solved]How to Insert a new field in design view? |
|
|
I would like to insert a new field in a saved table. However, when I edit a table in the design view, it is not possible to insert a new field in between two existing field? Is there any way to achieve that?
Last edited by hwtan on Mon Mar 31, 2008 9:37 pm; edited 1 time in total |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 Location: 3rd Rock From The Sun
|
Posted: Mon Mar 31, 2008 7:56 pm Post subject: |
|
|
hwtan:
You asked: | hwtan wrote: | | I would like to insert a new field in a saved table. However, when I edit a table in the design view, it is not possible to insert a new field in between two existing field? Is there any way to achieve that? |
Yes, it is possible to insert a new field (column) in between ( before ) an exsiting field (column ).
But, since it is a database . . . the ORDER of the fields ( columns ) should make NO difference.
However, if you are insistent on knowing . . . I will assume . . . you are using the Embedded OpenOffice database . . . HSQL . . . and . . . you can confirm this by looking at the status bar ( bottom ) of your opened database.
According to HSQL documentation at: http://www.hsqldb.org/doc/guide/ch09.html#alter_table-section
| Alter Table: http://www.hsqldb.org/doc/guide/ch09.html#alter_table-section wrote: |
ALTER TABLE
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>];
Adds the column to the end of the column list. The optional BEFORE <existingcolumn> can be used to specify the name of an existing column so that the new column is inserted in a position just before the <existingcolumn>. |
So, for example . . . let us assume . . . I have a Table with a name of My_Table and it contains a column ( field ) by the name of Country and you want to ADD a column ( field ) of City as VARCHAR(40) BEFORE Country . . . in this case:- Open your database file
- From the Menu: Tools -> SQL...
- Under Command to execute . . . enter the following SQL:
| Code: | | ALTER TABLE "My_Table" ADD COLUMN "City" VARCHAR(40) BEFORE "Country"; |
Press Execute button
Command successfully executed. should be displayed.
Press Close button
From the Menu: View -> Refresh Tables
Of course, change:- "My_Table"
- "Country"
- "City"
to the names in your database.
I hope this helps, please be sure to let me / us know.
Sliderule
Thanks to add [Solved] in your first post title (edit button) if your issue has been fixed / resolved. |
|
| Back to top |
|
 |
hwtan OOo Advocate


Joined: 24 Aug 2004 Posts: 320 Location: Singapore
|
Posted: Mon Mar 31, 2008 9:37 pm Post subject: |
|
|
| Thank you sliderrule. Although it is not as friendly as I would expect, it is a solution any way. Thanks once again. |
|
| Back to top |
|
 |
|