Results 1 to 5 of 5

Thread: Foreign key

  1. #1
    Join Date
    Apr 2009
    Posts
    15

    Question Unanswered: Foreign key

    Hi everyone,
    is it good to use explicitly foreign keys? what if i'm sure that my php will handle that things?
    do foreign keys affect on db efficiency?

    Thnx

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Acute View Post
    is it good to use explicitly foreign keys?
    absolutely yes

    Quote Originally Posted by Acute View Post
    what if i'm sure that my php will handle that things?
    you should still use foreign keys anyway

    php may not be the only way that you will ever want to enter information -- you might want to do data loads, for example

    Quote Originally Posted by Acute View Post
    do foreign keys affect on db efficiency?
    sort of

    they don't have any effect on SELECTs, but INSERTs and DELETEs are a very tiny bit slower

    what would you prefer -- an operation that is a tiny bit slower but guaranteed to result in correct data, or an operation that is a tiny bit faster but might result in incorrect data?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2009
    Posts
    15

    Question MyISAM

    Is it possible to use foreign keys in MyISAM

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Acute View Post
    Is it possible to use foreign keys in MyISAM
    well, not exactly "use" -- you can define them but they are ignored
    Quote Originally Posted by da manual
    InnoDB tables support checking of foreign key constraints. See Section 13.6, “The InnoDB Storage Engine”. Note that the FOREIGN KEY syntax in InnoDB is more restrictive than the syntax presented for the CREATE TABLE statement at the beginning of this section: The columns of the referenced table must always be explicitly named. InnoDB supports both ON DELETE and ON UPDATE actions on foreign keys. For the precise syntax, see Section 13.6.5.4, “FOREIGN KEY Constraints”.

    For other storage engines, MySQL Server parses and ignores the FOREIGN KEY and REFERENCES syntax in CREATE TABLE statements.

    -- http://dev.mysql.com/doc/refman/5.5/...ate-table.html
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Apr 2009
    Posts
    15

    Question So define them in MyISAM or not?

    So no need to even define them if they are ignored, right?

Tags for this Thread

Posting Permissions

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