Home » SQL & PL/SQL » SQL & PL/SQL » Foreign key
Foreign key [message #681814] |
Wed, 02 September 2020 04:54  |
 |
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   |
 |
EdStevens
Messages: 1375 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   |
 |
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: Tue Mar 28 10:34:57 CDT 2023
|