Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2007
    Posts
    1

    Unanswered: creating a trigger

    Hi, everyone, I am new here ...

    I have a problem to create a after-trigger (update).

    Example tables:

    CREATE TABLE R
    (
    log_num SMALLINT NOT NULL,
    int_num SMALLINT NOT NULL,
    beg_time TIME NOT NULL,
    end_time TIME NOT NULL,

    PRIMARY KEY (log_num, int_num),

    FOREIGN KEY skrbi(br_int) REFERENCES I (int_num)
    );

    CREATE TABLE I
    (
    int_num SMALLINT NOT NULL,
    name CHAR(50) NOT NULL,

    PRIMARY KEY (br_int),
    );

    CREATE TABLE S
    (
    mat_num SMALLINT NOT NULL,
    cost NUMERIC(7,2) NOT NULL,
    stored NUMERIC(7,2) NOT NULL WITH DEFAULT 0,

    PRIMARY KEY (br_mat),
    );

    CREATE TABLE IS
    (
    int_num SMALLINT NOT NULL,
    mat_num SMALLINT NOT NULL,
    norm NUMERIC (7,2) NOT NULL,

    PRIMARY KEY (int_num, mat_num),

    FOREIGN KEY fks(mat_num) REFERENCES S (mat_num),
    FOREIGN KEY fki(int_num) REFERENCES I (int_num)
    );

    I 1-many IS
    S 1-many IS
    R many-1 I


    When I insert new row into the table R, the adequate rows in table S should be updated. Few or one corresponding fields of column stored (table S) should be less for the size of the few or one corresponending norm (table IS).

    I am trying to write an update trigger that will send one or few (depends of the values of table IS) fields from one table (IS) to update one or few fields in another table (S, multiple rows though).



    Sorry if I asked something easy or stupid i am new to this, and my english is not so good.

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Can you correct the CREATE scripts so they run on DB2?
    When you've done that, I'll look further into it.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Also, tell us which version of DB2 you are using on which platform. And it would also be good to know the exact error messages you got (or the description of the behavior you see).
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

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