Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    104

    Unanswered: 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.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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)  
    );
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •