creating a trigger to update a record

  • How can I create a trigger to update rating to rating+1 if audio='choose one format' ?

    The database model is located below .

    http://imgur.com/cLxTm6K

  • Please post:

    - The relevant table(s) - in the form of a CREATE TABLE statement that I can copy/paste, not as an image; and do include all constraints and indexes, please

    - A few rows of carefully selected sample data to show the starting point - in the form if INSERT statements that we can copy/paste

    - A few data modification statements that should fire the trigger, and the desired end result in the table(s) after the statements and trigger have executed.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • e.hoxholli (2/15/2016)


    How can I create a trigger to update rating to rating+1 if audio='choose one format' ?

    The database model is located below .

    http://imgur.com/cLxTm6K

    Have you ever created a trigger before?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Try Books Online (https://msdn.microsoft.com/en-us/library/ms189799.aspx) - it is a great resource. Also, I recommend a beginners book on TSQL (Wrox has a good one IIRC).

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • e.hoxholli (2/15/2016)


    How can I create a trigger to update rating to rating+1 if audio='choose one format' ?

    The database model is located below .

    http://imgur.com/cLxTm6K

    Looking at the ERD you provided, you need to do a join from the Audio table through the DVD table using the AudioID and then join to the Movie table using the MovieID and then finally to the Rating Table using the RatingID. If you can provide that as an UPDATE statement, one of us can show you how to correctly fold it into a trigger (you have to have some of the fun ;-))

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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