Results 1 to 3 of 3

Thread: SQL server trigger help!

  1. #1
    srividhya Guest

    SQL server trigger help!

    hi!
    This trigger i made does not execute..........can anybody help?


    "Create TRIGGER update_status
    on book_issue
    for insert
    as
    update book_catalogue
    SET status='I' where book_catalogue.code = book_issue.code;
    go"

    I basically want the status of the book to change to 'I' in the book_catalogue whenever an entry is made in the book_issue.
    tables:
    book_catalogue
    book_issue

    P.S the problem realy is in the last sentence i.e, .........where book_catalogue.code=book_issue.code

  2. #2
    Mad Guest

    SQL server trigger help! (reply)

    You may have to specify the INSERTED table name to make a join in ur update clause.


    Create TRIGGER update_status
    on book_issue
    for insert
    as
    update book_catalogue
    FROM INSERTED
    SET status='I' where book_catalogue.code = INSERTED.code;
    go

    I hope this should work for you and meet the requiremnt.

    Thanx,
    MAD

    ------------
    srividhya at 5/10/01 11:16:24 AM

    hi!
    This trigger i made does not execute..........can anybody help?


    "Create TRIGGER update_status
    on book_issue
    for insert
    as
    update book_catalogue
    SET status='I' where book_catalogue.code = book_issue.code;
    go"

    I basically want the status of the book to change to 'I' in the book_catalogue whenever an entry is made in the book_issue.
    tables:
    book_catalogue
    book_issue

    P.S the problem realy is in the last sentence i.e, .........where book_catalogue.code=book_issue.code

  3. #3
    Ananth Guest

    SQL server trigger help! (reply)

    The way the trigger is written now, each time it will update ALL the matching rows, not just the newly entered row. Instead of

    SET status='I' where book_catalogue.code = book_issue.code
    use
    SET status='I' where book_catalogue.code = INSERTED.code

    Within the trigger, the pseudo table INSERTED will have the newly inserted data.


    ------------
    srividhya at 5/10/01 11:16:24 AM

    hi!
    This trigger i made does not execute..........can anybody help?


    "Create TRIGGER update_status
    on book_issue
    for insert
    as
    update book_catalogue
    SET status='I' where book_catalogue.code = book_issue.code;
    go"

    I basically want the status of the book to change to 'I' in the book_catalogue whenever an entry is made in the book_issue.
    tables:
    book_catalogue
    book_issue

    P.S the problem realy is in the last sentence i.e, .........where book_catalogue.code=book_issue.code

Posting Permissions

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