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

TRUNCATE on table does not take foreign keys in account

    XMLWordPrintable

Details

    Description

      • Logically TRUNCATE is same as DELETE but currently ON DELETE actions are not executed.

      CREATE TABLE author (
      id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
      name VARCHAR(100) NOT NULL
      ) ENGINE = InnoDB;
      CREATE TABLE book (
      id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
      title VARCHAR(200) NOT NULL,
      author_id SMALLINT UNSIGNED NOT NULL,
      CONSTRAINT `fk_book_author`
          FOREIGN KEY (author_id) REFERENCES author (id)
      ON DELETE CASCADE
      ON UPDATE RESTRICT
      ) ENGINE = InnoDB;
      INSERT INTO author (name) VALUES ('Abdul Alhazred');
      INSERT INTO book (title, author_id) VALUES ('Necronomicon', LAST_INSERT_ID());
      SELECT * FROM author;
      id	name
      1	Abdul Alhazred
      SELECT * FROM book;
      id	title	author_id
      1	Necronomicon	1
      TRUNCATE TABLE book;
      SELECT * FROM author;
      id	name
      1	Abdul Alhazred
      SELECT * FROM book;
      id	title	author_id
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jplindst Jan Lindström (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.