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

FOREIGN KEY can reference any KEY, not just PRIMARY KEY and UNIQUE

    XMLWordPrintable

Details

    Description

      A foreign key should only be able to reference a UNIQUE or PRIMARY KEY constraint, but MariaDB allows any key/index to be referenced. To reproduce:

      CREATE TABLE t1(c1 INT NOT NULL PRIMARY KEY,
        c2 INT NOT NULL,
        KEY(c2));
       
      CREATE TABLE t2(c1 INT NOT NULL PRIMARY KEY,
        c2 INT NOT NULL,
        FOREIGN KEY (c2) REFERENCES t1(c2));
      

      This is invalid in the SQL Standard as well as according to MariaDB Knowledge base: https://mariadb.com/kb/en/library/foreign-keys/ which states "The referenced columns must be a PRIMARY KEY or a UNIQUE index".

      Attachments

        Activity

          People

            JoeCotellese Joe Cotellese
            karlsson Anders Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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