Advertisement
Guest User

MySQL 5.1 still ignores foreign key constraints

a guest
Sep 13th, 2010
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.24 KB | None | 0 0
  1. % mysql test
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.
  3. Your MySQL connection id is 183
  4. Server version: 5.1.41-3ubuntu12.6 (Ubuntu)
  5.  
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7.  
  8. mysql> \W
  9. Show warnings enabled.
  10. mysql> create table foo(foo_id int primary key) engine=InnoDB;
  11. Query OK, 0 rows affected (0.00 sec)
  12.  
  13. mysql> create table bar(
  14.     ->     foo_id int references foo (foo_id)
  15.     -> ) engine=InnoDB;
  16. Query OK, 0 rows affected (0.01 sec)
  17.  
  18. mysql> show create table bar\G
  19. *************************** 1. row ***************************
  20.        Table: bar
  21. Create Table: CREATE TABLE `bar` (
  22.   `foo_id` int(11) DEFAULT NULL
  23. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  24. 1 row in set (0.00 sec)
  25.  
  26. /* ^ Notice the glaring lack of foreign key constraint?!?
  27.  * No errors, no warnings, no constraint.
  28.  *
  29.  * http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
  30.  *
  31.  * "Furthermore, InnoDB does not recognize or support “inline REFERENCES
  32.  * specifications” (as defined in the SQL standard) where the references are defined
  33.  * as part of the column specification. InnoDB accepts REFERENCES clauses only when
  34.  * specified as part of a separate FOREIGN KEY  specification."
  35.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement