Re: Foreign Keys Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Waynn Lue wrote:
As a side note, FKs do enforce other table specific properties like
indexes on the fields being constrained, so they do add value there as
well. But there's of course an extra cost on updates and inserts to
see if the FK is violated.

On the external table? No they don't.

mysql> create table t1(id int primary key, name varchar(255)) engine=innodb;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t2(t2id int, t1id int references t1(id)) engine=innodb;
Query OK, 0 rows affected (0.00 sec)

mysql> show create table t2\G
*************************** 1. row ***************************
       Table: t2
Create Table: CREATE TABLE `t2` (
  `t2id` int(11) default NULL,
  `t1id` int(11) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)


No auto-index on t2(t1id) at all. You have to define that yourself - you might want it part of a multi-column index for example.

You definitely should index it, but it won't happen automatically.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux