Home » SQL & PL/SQL » SQL & PL/SQL » Foreign key
Foreign key [message #681814] |
Wed, 02 September 2020 04:54 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/25dd36b323d8cd13dc66cf7312449111?s=64&d=mm&r=g) |
ttornado
Messages: 5 Registered: September 2020
|
Junior Member |
|
|
Hi,
I have a doubt: having to create two tables
TABLE1 (A,B,C) AND TABLE2(E,F,G,H), is it possible to define for the TABLE2 (two columns G,H of table2 having for foreign key the same column C of talbe1)?
CREATE TABLE TABLE2
(
E ...,
F ...,
G ...INT,
H ... INT,
FOREIGN KEY (G, H)
REFERENCES TABLE1 (C)
);
Thanks a lot
TT
|
|
|
|
|
|
|
|
|
|
Re: Foreign key [message #681838 is a reply to message #681814] |
Thu, 03 September 2020 11:15 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/d29f577f753cb4b873212fd5ed0da4cd?s=64&d=mm&r=g) |
EdStevens
Messages: 1376 Registered: September 2013
|
Senior Member |
|
|
ttornado wrote on Wed, 02 September 2020 04:54Hi,
I have a doubt: having to create two tables
TABLE1 (A,B,C) AND TABLE2(E,F,G,H), is it possible to define for the TABLE2 (two columns G,H of table2 having for foreign key the same column C of talbe1)?
CREATE TABLE TABLE2
(
E ...,
F ...,
G ...INT,
H ... INT,
FOREIGN KEY (G, H)
REFERENCES TABLE1 (C)
);
Thanks a lot
TT
Is it possible?
What happened when you tried it for yourself?
|
|
|
Re: Foreign key [message #681843 is a reply to message #681838] |
Thu, 03 September 2020 13:18 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/25dd36b323d8cd13dc66cf7312449111?s=64&d=mm&r=g) |
ttornado
Messages: 5 Registered: September 2020
|
Junior Member |
|
|
EdStevens wrote on Thu, 03 September 2020 18:15ttornado wrote on Wed, 02 September 2020 04:54Hi,
I have a doubt: having to create two tables
TABLE1 (A,B,C) AND TABLE2(E,F,G,H), is it possible to define for the TABLE2 (two columns G,H of table2 having for foreign key the same column C of talbe1)?
CREATE TABLE TABLE2
(
E ...,
F ...,
G ...INT,
H ... INT,
FOREIGN KEY (G, H)
REFERENCES TABLE1 (C)
);
Thanks a lot
TT
Is it possible?
What happened when you tried it for yourself?
Hi,
I tried it and got an error. But trying with
CONSTRAINT FK_TAB2_TAB1_G FOREIGN KEY(G) REFERENCES TABLE1 (C),
CONSTRAINT FK_TAB2_TAB1_H FOREIGN KEY(H) REFERENCES TABLE1 (C)
is OK
Thank you
TT
|
|
|
|
Goto Forum:
Current Time: Sat Jun 29 18:07:08 CDT 2024
|