Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2009
    Posts
    6

    Exclamation Unanswered: Help with Triggers! (homework)

    This is what I had to do for my assigment!! I am just checking if this is correct!! Any help would be nice!! Thank You in Advance!

    Create and test the following triggers for the database created in Programming Assignment 6.

    1. A trigger that prevents the number of miles on a truck from being decreased.

    This what I did for this one!

    CREATE TRIGGER TURCK_MILES ON TRUCK
    FOR INSERT,UPDATE
    AS
    declare @v1 decimal(8,2)
    declare @v2 decimal(8,2)
    select @v1 = TRUCK_MILES FROM TURCK
    BEGIN
    ROLLBACK
    END


    2. A trigger that prevents the Buy Date for truck from being after the current date.

    This is what I put!

    CREATE TRIGGER TRUCK_BUY_DATE ON TRUCK
    FOR INSERT,UPDATE
    AS
    declare @date DATETIME
    select @date=inserted.TRUCK_BUY_DATE FROM INSERTED
    IF @date>GETDATE()
    BEGIN
    ROLLBACK TRANSACTION
    END


    3. A trigger that ensures that the Base Code in the Truck table is always in the Base table

    My Answer!

    CREATE TRIGGER BASE_CODE ON TRUCK
    FOR INSERT,UPDATE
    AS
    declare @1_base_code int
    declare @2_base_code int
    select @1_base_code=inserted.BASE_CODE
    FROM INSERTED,BASE,TRUCK
    IF @1_base_code<>@2_base_code
    BEGIN
    ROLLBACK TRANSACTION
    END

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    All three of these triggers need some work. You appear to have a good grasp of some concepts, but need some work on others, which is pretty common when learning new material.

    Based on the way that these specifications are worded, they all imply joins between the INSERTED pseudo-table and the base table combined with a conditional ROLLBACK based on the result of the join.

    I won't do your homework for you (if I appear to do it for you, you should be VERY suspicious ), but I'll give you guidance and will tell you when I think you've got things right.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Nov 2009
    Posts
    6

    Need More Detail Help!!

    If you do not mind please explain in more detail and more showing me what to do...Thank You!
    Last edited by JoGo1; 11-15-09 at 10:41.

Posting Permissions

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