Results 1 to 2 of 2

Thread: create trigger

  1. #1
    Join Date
    Mar 2008
    Posts
    136

    Unanswered: create trigger

    There are two table A and B.

    Fields of A :- Aid(PK), name, isactive, cdate, Bid

    Fields of B:- Bid(PK),name,isactive ,cdate



    There is no FK relation between A and B.



    Trigger1:- If I insert new rocord in table A, new record with this data must be inserted in B table automatically. And Bid of table A must be updated by Bid of B in same record.

    Example:

    Insert into A values(1,’Pawan’,’Y’,’2008-10-16’);

    After inserting this record data must be like below in tables….

    Table A

    1

    Pawan

    Y

    2008-10-16

    10



    Table B

    10

    Pawan

    Y

    2008-10-16



    Trigger2:- If I update any value in any record in table A, same must be updated in table B respectively.

    Example:

    Update A set name=’Kumar’ where Aid=1;

    After this update data must be like below in tables..



    Table A

    1

    Kumar

    Y

    2008-10-16

    10



    Table B

    10

    Kumar

    Y

    2008-10-16
    Regards
    Pawan Kumar

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you should think about combining your two tables instead of this complicated trigger scheme
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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