Foreign /primary key [message #10130] |
Tue, 06 January 2004 02:15 |
Furdah
Messages: 3 Registered: January 2004
|
Junior Member |
|
|
ANother dumb question perhaps from me
I have A table "res" with a primary key which consist out of 3 table-elements (res-id,res-Loc,res-date)
NOw have i a second table 'optREs' (this contains options about reservations)
how would i now reference from the 'optres' table to 'res'table ???? If anybody understand this freaky language of me , my english isn't that well
Grtz & thnx
|
|
|
Re: Foreign /primary key [message #10131 is a reply to message #10130] |
Tue, 06 January 2004 02:32 |
Ken Jones
Messages: 70 Registered: January 2004
|
Member |
|
|
CREATE TABLE optREs(
columns datatypes,
columns datatypes,
columns datatypes,
CONSTRAINT FK_optREs
FOREIGN KEY (res-id,res-Loc,res-date)
REFERENCES RES (res-id,res-Loc,res-date)) ;
|
|
|
Re: Foreign /primary key [message #10162 is a reply to message #10130] |
Tue, 06 January 2004 23:07 |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
When the PK consists of multiple columns you have to decide whether you want to repeat them on all detail tables, or whether it would be better to give the table a generated ('surrogate') primary key using a sequence and make the column combination an ordinary unique key instead. It is perfectly valid either way, it just depends on things like how many detail tables there are, how much data there will be, how you want to use it etc.
btw RES and OPTRES are kind of cryptic as table names. You can use up to 30 characters - what's wrong with "RESERVATIONS" etc?
|
|
|