Hello.

I have a problem on "ALTER TABLE ... ADD FOREIGN KEY".

I'm using InnoDBs, and I wanna create Foreign Key after table has been created.

But, 'ALTER TABLE .. ADD FOREIGN KEY" does not work.

Manual says :

The FOREIGN KEY, CHECK, and REFERENCES clauses don't actually do anything

And in my test, 'ALTER .... ADD FOREIGN KEY' does not create FK.

mysql> CREATE TABLE `CONS_PARENT` (
    ->   `A` int(11) NOT NULL default '0',
    ->   `B` int(11) NOT NULL default '0',
    ->   UNIQUE KEY `A` (`A`,`B`) ) Type=InnoDB ;
Query OK, 0 rows affected (0.02 sec)

mysql> CREATE TABLE `CONS_CHILD` (
    ->   `A` int(11) NOT NULL default '0',
    ->   `B` int(11) NOT NULL default '0',
    ->   KEY `A` (`A`,`B`)
    -> ) TYPE=InnoDB ;
Query OK, 0 rows affected (0.05 sec)

mysql> ALTER TABLE CONS_CHILD ADD CONSTRAINT FOREIGN KEY CONS_CHILD_FK ( A , B )
REFERENCES CONS_PARENT  ON DELETE CASCADE ;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

# See Below! FK does not EXIST
mysql> SHOW CREATE TABLE CONS_CHILD ;
+------------+------------------------------------------------------------------
---------------------------------------------------------------------+
| Table      | Create Table
|
+------------+------------------------------------------------------------------
---------------------------------------------------------------------+
| CONS_CHILD | CREATE TABLE `CONS_CHILD` (
  `A` int(11) NOT NULL default '0',
  `B` int(11) NOT NULL default '0',
  KEY `A` (`A`,`B`)
) TYPE=InnoDB |
+------------+------------------------------------------------------------------
---------------------------------------------------------------------+
1 row in set (0.00 sec)



Does any body know how can create FK after tables creates?

Thank you. Have a nice weekend!




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to