Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    India
    Posts
    13

    Unanswered: How to create a column who value is derived from two other columns ??

    If there are two columns in table, named column A and column B, Can we add one more column C to the table which would always have sum of A and B. If value of A or B is changed, the value of A + B should automaticaly get reflected in varlable C.

    Please, let me know what are the ways in which this can be accomplished in DB2.
    Thanks
    Ranjith

  2. #2
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513

    Re: How to create a column who value is derived from two other columns ??

    Originally posted by ranjir75
    If there are two columns in table, named column A and column B, Can we add one more column C to the table which would always have sum of A and B. If value of A or B is changed, the value of A + B should automaticaly get reflected in varlable C.

    Please, let me know what are the ways in which this can be accomplished in DB2.
    Triggers.
    --
    Jonathan Petruk
    DB2 Database Consultant

  3. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    You can also use:

    ALTER TABLE TableA add column COL_C INTEGER generated always as (COL_A + COL_B).

    Andy

Posting Permissions

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