Bug #3238 Stored Procedure CREATE TABLE with foreign key clause fails
Submitted: 18 Mar 2004 17:56 Modified: 28 Sep 2004 15:25
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.1-alpha-debug OS:Linux (SuSE 8.2)
Assigned to: Per-Erik Martin CPU Architecture:Any

[18 Mar 2004 17:56] Peter Gulutzan
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)
[28 Sep 2004 15:25] Per-Erik Martin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

This is no longer repeatable.