Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7546

Different behavior of foreign keys in CREATE TABLE statements

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Not a Bug
    • 5.5.33a
    • N/A
    • Parser
    • Suse Linux 13.1

    Description

      Inconsistent behavior in CREATE TABLE statements: When foreign key statements are listed directly behind attributes they do not get a constraint while the get one if the foreign keys statements are listed separately after all attributes. The following examples will demonstrate this:

      Welcome to the MariaDB monitor.  Commands end with ; or \g.
      Your MariaDB connection id is 1
      Server version: 5.5.33-MariaDB openSUSE package
       
      Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
       
      MariaDB [(none)]> create database testdb;
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [(none)]> use testdb;
      Database changed
      MariaDB [testdb]> create table t(id int primary key);
      Query OK, 0 rows affected (0.01 sec)
       
      MariaDB [testdb]> show create table t;
      +-------+-------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                          |
      +-------+-------------------------------------------------------------------------------------------------------+
      | t     | CREATE TABLE `t` (
        `id` int(11) NOT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
      +-------+-------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [testdb]> create table t2(id int, t_id int, foreign key (t_id) references t(id));
      Query OK, 0 rows affected (0.02 sec)
       
      MariaDB [testdb]> show create table t2;
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                                                      |
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t2    | CREATE TABLE `t2` (
        `id` int(11) DEFAULT NULL,
        `t_id` int(11) DEFAULT NULL,
        KEY `t_id` (`t_id`),
        CONSTRAINT `t2b_ibfk_1` FOREIGN KEY (`t_id`) REFERENCES `t` (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [testdb]> create table t3(id int, t_id int references t(id));
      Query OK, 0 rows affected (0.02 sec)
       
      MariaDB [testdb]> show create table t3;
      +-------+---------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                        |
      +-------+---------------------------------------------------------------------------------------------------------------------+
      | t3    | CREATE TABLE `t3` (
        `id` int(11) DEFAULT NULL,
        `t_id` int(11) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
      +-------+---------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [testdb]> 

      Attachments

        Activity

          People

            Unassigned Unassigned
            pintman Marco Bakera
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.