If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > changing foreign key name

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-09, 19:06
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
changing foreign key name

Is there a long-term problem I'm not seeing with using one name for a foreign key in a child table that references a key by another name in the parent?

eg.
Code:
CREATE TABLE equipment_standstreated
(
    equipmenttypeID          INTEGER     NOT NULL
    standtreatedID             INTEGER     NOT NULL
,   PRIMARY KEY (equipmenttypeID, standtreatedID)
,   CONSTRAINT equipmenttypeID_fk
        FOREIGN KEY equipmenttypeID
            REFERENCES equipmenttypes (equipmenttypeID)
,   CONSTRAINT standstreatedID_fk
        FOREIGN KEY standstreatedID
           REFERENCES standstreated (standsID)  
);
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
  #2 (permalink)  
Old 03-31-09, 12:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
not sure i understand your question, but the above syntax is wrong

you can use whatever name you want for the foreign key, i.e. standstreatedID is perfectly okay when referencing standsID in standstreated

the syntax error is due to the missing parentheses
Code:
CREATE TABLE equipment_standstreated
(
    equipmenttypeID          INTEGER     NOT NULL
    standtreatedID             INTEGER     NOT NULL
,   PRIMARY KEY (equipmenttypeID, standtreatedID)
,   CONSTRAINT equipmenttypeID_fk
        FOREIGN KEY ( equipmenttypeID )
            REFERENCES equipmenttypes (equipmenttypeID)
,   CONSTRAINT standstreatedID_fk
        FOREIGN KEY ( standstreatedID )
           REFERENCES standstreated (standsID)  
);
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-31-09, 14:20
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
resolved

Thanks R,

That does answer my question. My apologies for the syntax error; my sloppiness.
__________________
In theory, there is no difference between theory and practice. In practice there is.
Disputed Origins

Ninety-three percent of all statistics are made-up on the spot.
Ancient proverb.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On