SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Foreign key to more tables?

    Is it possible to define a foreign key to more tables? I tried something like this but I get error when creating the table in phpmyadmin:

    Code:
        // ...
        FOREIGN KEY (post_id)
            REFERENCES posts(id)
            ON DELETE CASCADE,
        FOREIGN KEY (post_id)
            REFERENCES posts_fulltext(id)
            ON DELETE CASCADE,
        // ...

  2. #2
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't say for sure but, you may find it easier if we normalise things a bit more.

    please post your create table statement for the three tables you are referring to.

    bazz

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i don't know if it's possible or not, but it doesn't make any sense

    in order for this to work, the two referenced tables would have to have exactly the same set of PKs, which wouldn't make sense (the tables should be combined)

    but then... looking at the names of the tables, it's easy to deduce why they were set up as separate -- one of them's the "main" table, while the other one is separate only in order to enable fulltext indexing

    but fulltext indexing is possible only on myisam tables

    ... and myisam tables don't support foreign keys

    so the idea wouldn't work anyway

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    .... it's easy to deduce why ....


    bazz


Bookmarks

Posting Permissions

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