Foreign key Primary key Relation [message #553237] |
Wed, 02 May 2012 11:10  |
newbie3
Messages: 23 Registered: September 2010
|
Junior Member |
|
|
Hello Guys,
I am trying to establish PK-FK relationship between 2 tables. Table 1 has VACC_ID as a primary key. Table 2 has VACC_ID and SCH_ID as the primary keys. I am trying to add VACC_ID from Table 2 as a FK to Table 1. This is the code I used
ALTER TABLE Table_1
ADD CONSTRAINT FK_VACC_ID
FOREIGN KEY (VACC_ID)
REFERENCES Table_2(VACC_ID)
I also tried to add it without writing the query and editing the Table 1. By default, I am getting 2 columns(both VACC_ID) in the local column being referenced to the 2 primary keys(VACC_ID and SCH_ID) of table 2. Please let me know, how to resolve this. I also uploaded the screeshot of the error, when I run the query. Thank You.
|
|
|
|
|
|
|