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

Can't redefine constraint in a single ALTER TABLE

    XMLWordPrintable

Details

    Description

      It is possible to use one ALTER TABLE to drop and create a new column or index. This is not possible with a constraint; there will an error. See below

      CREATE TABLE abc (id INT NOT NULL, PRIMARY KEY (id));
       
      CREATE TABLE def (
      	abc_id INT NOT NULL, 
      	droppable_column INT NOT NULL,
      	INDEX droppable_index(abc_id),
      	CONSTRAINT constraint_name FOREIGN KEY (abc_id) REFERENCES abc (id)
      );
       
      # No problem
      ALTER TABLE def
      DROP COLUMN droppable_column ,
      ADD COLUMN droppable_column INT NOT NULL;
       
      # No problem
      ALTER TABLE def
      DROP INDEX droppable_index,
      ADD INDEX droppable_index(abc_id);
       
      # Problem
      ALTER TABLE def
      DROP FOREIGN KEY constraint_name,
      ADD CONSTRAINT constraint_name FOREIGN KEY (abc_id) REFERENCES abc (id);
      

      Attachments

        Issue Links

          Activity

            People

              vlad.lesin Vladislav Lesin
              user2180613 Remy Fox
              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.