Page 1 of 1

Primary Key

Posted: Sun Feb 10, 2008 3:50 am
by levinefa
I took a basic database course two years ago but for the life of me I cannot remember how to do a primary key/foriegn key. If it helps any, I am using open office on parallels, on my mac, so i do not have a right click button (the way to do it on a mac is to press the apple/command key but in parallels that opens the start menu). i think that i looked everywhere for it, even going to the help menu, but nothing in the help menu said where to go to make one, just what it does. if you can help me, i would really appreciate it. thanks!

Re: Primary Key

Posted: Sun Feb 10, 2008 4:18 am
by DrewJensen
levinefa wrote:I took a basic database course two years ago but for the life of me I cannot remember how to do a primary key/foriegn key. If it helps any, I am using open office on parallels, on my mac, so i do not have a right click button (the way to do it on a mac is to press the apple/command key but in parallels that opens the start menu). i think that i looked everywhere for it, even going to the help menu, but nothing in the help menu said where to go to make one, just what it does. if you can help me, i would really appreciate it. thanks!
You do NOT have a right click button....how do you manage to face the world?

Well, they only way in the GUI is with a right mouse click...but you are not lost.

Say you have a table named Table1 and it has a field named ID and you want to make the ID field the primary key.

First - if you are using the embedded database you can simply do this - the first field of type INTEGER or BIGINT that you set as Auto_increment will automatically be set as a type IDENTITY ( you will notice this in the UI is you watch when you set the property ) and when you save the table the GUI will ask - Do you want to create a Primary Key field - if you say NO and just save the table - the Primary Key is created because all fields of tyep IDENTITY under HSQLdb are Primary Keys ( an you can have exactly 0 or 1 in any given table )

Second - if whe the GUI asked - Do you want to create a primary key field you ansered yes it would prepend a field named ID to the table of type INTEGER and make it the primary key, but alwas it would not be auto_incrementing - in other words not of type IDENTITY.

Third - say you are going to use a "Natural Key", meaning something that is real like a code number. Again assume the table is named Table1 and the field you want for the PK is named CodeValue. Create the table and when you save it answer NO to the prompt to adda primiary key.
Now close the table designer and open the SQL window ( Tools>SQL ) and enter the following command:
ALTER TABLE "Table1" ADD PRIMARY KEY ( "CodeVal" )
Click on the Execute button.

You can find the documentation for the ALTER TABLE command and the ADD PRIMARY KEY sub command at http://hsqldb.org/web/hsqlDocsFrame.html

HTH

Re: Primary Key

Posted: Sun Feb 10, 2008 4:23 am
by levinefa
thank you so much! and when im on the mac side of my computer its fine, just when i need to use open office, thats when i regret not having a wireless mouse with a right click button with me haha.

Re: Primary Key

Posted: Sun Feb 10, 2008 4:26 am
by DrewJensen
Will you be looking at switching to the Aqua release when it is ready then?
Or do I sinply expose once again my utter lack of knowledge about Macs?

Re: Primary Key

Posted: Thu Feb 21, 2008 12:10 pm
by wurzel
DrewJensen wrote:Or do I sinply expose once again my utter lack of knowledge about Macs?
Hi Drew,

Partly :-p

I'm rather surprised that the original poster is using Parallels for working with OOo, since there is a fairly large choice of existing OOo solutions available to him on the Mac, for which either the Ctrl or Cmd (little Apple symbol key) combos work.

NeoOffice : latest version 2.2.2, fixpack 11, soon to be 2.3 (from when I last looked)

OpenOffice.org 2.3.1 stable for X11

OpenOffice.org 2.4.0 Release Candidate 1 for X11 : undergoing quality assurance testing at the moment, will be more or less the next stable version to come out for X11

OpenOffice.org 2.4.0 Aqua RC1 : inappropriately named testing version, not yet production work ready, crashes still fairly often (especially with Base) but mostly OK

SRC680_m247 : development version of the future 3.0 codebase, unstable, incomplete, etc, etc.

All of these are available from the ooopackages.good-day.net ftp server.


Alex

Re: Primary Key

Posted: Thu Feb 21, 2008 3:58 pm
by DrewJensen
wurzel wrote:
DrewJensen wrote:Or do I sinply expose once again my utter lack of knowledge about Macs?
Partly :-p
Okie Dokie ...still batting a thousand on the subject then.