Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    foreign key to another db on same server - question

    Hi,

    in phpMyAdmin, I have created a table with a foreign key, which references a pk from another table in another db, on the same server.

    It didn't error and the table was created so I wonder does that prove that a fk can ref a pk in another db?

    I have read loads online about it - a mixture of yes you can do it to no you can't. no clarity on which mysql they speak of but they say even oracle can;t do it.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Well wait a sec, did you create the FK constraint, or just the two tables?

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    I created the table in the second db and included its constraint.
    Edit:
    The first tbale was already created.


    Code:
    , CONSTRAINT season_business_fk                   
        FOREIGN KEY ( business_id)                    
          REFERENCES first_db.business_details ( business_id )                
    ) ENGINE=INNODB DEFAULT CHARSET=LATIN1
    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,232
    Thanks
    80
    Thanked 4,456 Times in 4,421 Posts
    Given that you can easily utilize tables in other DBs in any MySQL query, I don't think the capability is surprising. Well, maybe somewhat surprising, but not exactly amazing.


  •  

    Posting Permissions

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