Description:
I can create a table with a foreign key, and when I use SHOW CREATE TABLE to check, I
find that the foreign key is there. But if I do the same create-table statement within a stored
procedure, when I use SHOW CREATE TABLE to check, the FOREIGN KEY clause is
missing.
How to repeat:
mysql> create table t2 (s1 int, primary key (s1)) engine=innodb;
Query OK, 0 rows affected (0.50 sec)
mysql> create table t3 (s1 int, key (s1), foreign key (s1) references t2 (s1)) engine=innodb;
Query OK, 0 rows affected (0.31 sec)
mysql> create procedure p35 () create table t4 (s1 int, key (s1), foreign key (s1) references
t2 (s1)) engine=innodb;
Query OK, 0 rows affected (0.00 sec)
mysql> call p35();
Query OK, 0 rows affected (0.32 sec)
mysql> show create table t3;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table
|
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (
`s1` int(11) default NULL,
KEY `s1` (`s1`),
CONSTRAINT `0_354` FOREIGN KEY (`s1`) REFERENCES `t2` (`s1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show create table t4;
+-------+-----------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------+
| t4 | CREATE TABLE `t4` (
`s1` int(11) default NULL,
KEY `s1` (`s1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)