How to use Trigger

  • Hi friends.....

    I created a report using JSP, for that report i've used around 15 tables, using JOINS i used them. Now I need to create a trigger to get the values which is updated along with new value....

    Suggest me to create a trigger

  • check "create trigger" in books online.

    http://msdn.microsoft.com/en-us/library/ms189799%28v=SQL.90%29.aspx

    Golden rule for triggers: keep it short, as it is performed "in transaction", so if the trigger fails, the transaction fails !

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Hi.. Thanks...

    I've created a trigger... it is inserting also.

    But i should insert based on some key or it should update that row.

    s der any suggestion to SELECT a column from 1 table and to compare with the same in trigger table, if this constraint satisfies den only it should Update, if not should insert along with the key....

  • Please elaborate on what you are actually trying to do !

    Triggers can perform queries, but keep the transaction scope and locking in mind !

    Special objects _in_ triggers are the "inserted" and "deleted" object.

    Deleted will hold the previous data,

    inserted contains the new data.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • On Update of a particular column in 1 table i've created trigger which will store the updated value along with table1's primary key,

    if i again update that column then also it'll insert the updated column value and its primary key,

    So, in my new table that primary key's of original table is repeating...

    i don't want it to repeat...

    what i need is if that row is present in my table table then it should update rest of fields, if not trigger should insert all the values with primary key, so that i can not have duplicates in new table... and i came use that for generating reports....

  • Please explain clearer and in more detail with some table definitions.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Mr.

    I sorted my problem....

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply