Using Trigger to populate another table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • June Moore

    Using Trigger to populate another table

    Hi all,
    I have two tables tbl_A and tbl_B.
    Table Definitions:
    tbl_A (field_1, field_2, field_3)
    tbl_B (field_1, field_2)
    I would like to populate tbl_B when a record is inserted into tbl_A.
    Note that tbl_A.field_1 = tbl_B.field_1 and tbl_A.field_2 =
    tbl_B.field_2 .

    How do I write a trigger on tbl_A to get the corresponding record
    inserted into tbl_B?

    Regards
    June.....
  • sampangi

    #2
    Re: Using Trigger to populate another table

    Try

    Create trigger tbl_AIns on tbl_A
    for Insert as
    begin
    INSERT tbl_B
    Select field_1
    , field_2
    from INSERTED
    End

    HTH,
    Srinivas Sampangi


    "June Moore" <jungewum@yahoo .com.au> wrote in message
    news:e5dfaf21.0 308202051.283c3 82f@posting.goo gle.com...[color=blue]
    > Hi all,
    > I have two tables tbl_A and tbl_B.
    > Table Definitions:
    > tbl_A (field_1, field_2, field_3)
    > tbl_B (field_1, field_2)
    > I would like to populate tbl_B when a record is inserted into tbl_A.
    > Note that tbl_A.field_1 = tbl_B.field_1 and tbl_A.field_2 =
    > tbl_B.field_2 .
    >
    > How do I write a trigger on tbl_A to get the corresponding record
    > inserted into tbl_B?
    >
    > Regards
    > June.....[/color]


    Comment

    • Jens Süßmeyer

      #3
      Re: Using Trigger to populate another table

      Hello June !

      Try this

      The statement in the trigger is:

      Insert into table2
      Select field_1,field_2 from inserted

      Jens Süßmeyer.

      "June Moore" <jungewum@yahoo .com.au> schrieb im Newsbeitrag
      news:e5dfaf21.0 308202051.283c3 82f@posting.goo gle.com...[color=blue]
      > Hi all,
      > I have two tables tbl_A and tbl_B.
      > Table Definitions:
      > tbl_A (field_1, field_2, field_3)
      > tbl_B (field_1, field_2)
      > I would like to populate tbl_B when a record is inserted into tbl_A.
      > Note that tbl_A.field_1 = tbl_B.field_1 and tbl_A.field_2 =
      > tbl_B.field_2 .
      >
      > How do I write a trigger on tbl_A to get the corresponding record
      > inserted into tbl_B?
      >
      > Regards
      > June.....[/color]


      Comment

      Working...