Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2016
    Posts
    1

    Unanswered: insert foreign keys with trigger

    Hello.
    I need a lot of help with a problem I just can't resolve.
    I got the following tables :
    Code:
    CREATE TABLE A (
      id_a INT AUTO_INCREMENT PRIMARY KEY,
      name_a VARCHAR(50),
      surname_a VARCHAR(50));
    Code:
    CREATE TABLE B(
    id_b INT AUTO_INCREMENT PRIMARY KEY,
    name_b VARCHAR(50),
    surname_b VARCHAR(50),
    unique bbb(name_b,surname_b));
    Code:
    CREATE TABLE C(
    id_c INT AUTO_INCREMENT PRIMARY KEY,
    cab VARCHAR(40) UNIQUE);
    Code:
    CREATE TABLE D(
    id_as INT,
    id_bs INT,
    id_cs INT,
    dt DATETIME,
    FOREIGN KEY(id_as) REFERENCES A(id_a),
    FOREIGN KEY(id_bs) REFERENCES B(id_b),
    FOREIGN KEY(id_cs) REFERENCES C(id_c));
    Code:
    CREATE TABLE E(
    dat DATE,
    ora TIME,
    name_b VARCHAR(50),
    surname_b VARCHAR(50),
    name_a VARCHAR(50),
    surname_a VARCHAR(50),
    cab VARCHAR(40));
    Ok. Table A and table E are populated with a load file process. We will leave table A aside for now.
    I am using a trigger on table E to populate tables B, C and D. The trigger has a continue handler for duplicate entries. I managed so far to populate tables B and C but I have REAL trouble on doing the same with table D. I can't find a way to get the primary keys into that table. I've tried to get them into a variable by using the handler's duplicate flag but is not working. Any ideas ? Any help would be highly appreciated. Thank you.
    Last edited by k4bras; 07-21-16 at 17:25.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •