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 > Foreign key

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-11, 14:33
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Question 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
Reply With Quote
  #2 (permalink)  
Old 01-08-11, 16:18
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-08-11, 22:16
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Question MyISAM

Is it possible to use foreign keys in MyISAM
Reply With Quote
  #4 (permalink)  
Old 01-08-11, 22:31
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-08-11, 22:49
Acute Acute is offline
Registered User
 
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?
Reply With Quote
Reply

Tags
foreign, key

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