Bug #10470 Duplicate/conflicting foreign key constraint can be added using alter table.
Submitted: 9 May 2005 11:31 Modified: 9 May 2005 11:37
Reporter: Disha Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.0.5 Beta OS:Windows (Windows 2003)
Assigned to: CPU Architecture:Any

[9 May 2005 11:31] Disha
Description:
Duplicate or conflicting foreign key constraint can be added using the alter table command.

How to repeat:
1. Start the MySQL client and connect to the database with valid user and password.
2. Set the delimiter to // and use the test database.
3. Create a table as follows:
   
   create table t1(
      f1 int, f2 char(100),
      primary key(f1)
   )engine=innodb//

4. Create another table with foreign key to column f1 of table t1 with the ON DELETE SET DEFAULT option:
   
   create table t2(f1 int default 0, f2 char(100),
   foreign key (f1) references t1(f1) ON DELETE SET NULL
   )engine=innodb//

5. Now add the same constraint can be added through alter table:
   alter table t2 add foreign key (f1) references t1(f1) ON DELETE SET NULL//

6. Also try to add same constraint with different option using the alter table command as follows:
   alter table t2 add foreign key (f1) references t1(f1) ON DELETE RESTRICT//

Expected Results: 
1. Error should be displayed for duplicate foreign key constraint.

Actual Results: 
1. No error is displayed and conflicting foreign key constraints are accepted.
2. The output of show creates table statement shown below displays the duplicate constraints.

mysql> show create table t2//
+-------+---------------------------------------------------------------------------------------
| Table | Create Table
+-------+---------------------------------------------------------------------------------------
| t2    | CREATE TABLE `t2` (
  `f1` int(11) default '0',
  `f2` char(100) default NULL,
  KEY `f1` (`f1`),
  CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`),
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON DELETE SET NULL,
  CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------
1 row in set (0.00 sec)

mysql>
[9 May 2005 11:37] Jan Lindström
This is duplicate of #10354. You can have several foreign key constraints defined to same column.

Regards,
    JanL