Working with triggers

Discussion in 'MySQL' started by Atabek, Jun 5, 2011.

  1. #1
    Hello friends!
    Let's consider, we have 3 tables:

    tabel1:
    -------
    id | subjects | local_idx
    -------------------------
    1 | s1 | 1
    2 | s2 | 25
    3 | s3 | 14
    ...


    A group has got some subjects only one time, e.g group a1 has subject s1 only one time:

    table2:
    -------
    id | groups | local_idx | subjects
    ---------------------------------------------------
    1 | a1 | 1 | s1
    2 | a2 | 2 | s1
    3 | a1 | 1 | s2
    5 | a2 | 2 | s3
    6 | a3 | 3 | s1
    7 | a1 | 1 | s3
    8 | a2 | 2 | s2
    ...


    Everytime we insert new record in table2, table3 must have such kind of results:

    table3:
    -------
    id | local_idx (from table2) | local_idx (from table1)
    ------------------------------------------------------
    1 | 1 | 1
    2 | 2 | 1
    3 | 1 | 25
    4 | 2 | 14
    5 | 3 | 1
    6 | 1 | 14
    7 | 2 | 25
    ...

    For example, when we insert (in table2) group a3 with local_idx 3 and subject s2 (which local_idx's 14)
    then result must be:
    8 | 3 | 14
     
    Atabek, Jun 5, 2011 IP
  2. Atabek

    Atabek Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Any ideas, please.
     
    Atabek, Jun 5, 2011 IP
  3. Atabek

    Atabek Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    May be triggers can't help me... :-(
     
    Atabek, Jun 7, 2011 IP
  4. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Triggers are used to give the ristrictions in performing applications example:
    A bank wants to stop the transaction on sunday , So this can be done in database using triggers.
     
    unknownpray, Jun 24, 2011 IP
  5. Atabek

    Atabek Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank You.
     
    Atabek, Jun 24, 2011 IP