Results 1 to 8 of 8

Thread: More Help with Trigger.

  1. #1
    Join Date
    Jul 2005
    Posts
    6

    More Help with Trigger.

    Newbie.

    Create an update Trigger on the Carrier Table that will display the all the fields and records in the Inserted, Deleted, and Carrier Table.

    This is the Table.

    Create Table Paper

    (
    PaperID smallint identity(1,1) Not Null /* a paper id can not be blank. Data has to be there*/
    Constraint PK_Paper Primary Key Clustered,
    PaperName varchar(30) Not Null
    )

    Thanks,
    Last edited by calthi; 07-18-2005 at 10:41 AM.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can do select * on inserted and deleted tables. But if you do select * on carrier table then you will get all the rows not just the updated rows. to get only the updated rows, you have to join it with inserted or deleted table.

  3. #3
    Join Date
    Feb 2003
    Posts
    1,048
    Triggers do not return data to the user!! If you are tryting to get the trigger to display data for you, it won't work.

  4. #4
    Join Date
    Jul 2005
    Posts
    6
    Wow, I did not know that Trigger do not return data to the user. But this question is used by my instructor for the lab. Humm????

  5. #5
    Join Date
    Feb 2003
    Posts
    1,048
    What is the exact question from the instructor?

    And to correct myself, a trigger SHOULD NOT return any results back to the user, but it is basically just a stored procedure, so it will return results back like any other stored procedure.

    An instructor should not be teaching you to do this however!!!!

  6. #6
    Join Date
    Jul 2005
    Posts
    6
    The question is like this:

    Create an update Trigger on the Carrier Table that will display the all the fields and records in the Inserted, Deleted, and Carrier Table.

  7. #7
    Join Date
    Feb 2003
    Posts
    1,048
    Well, it will work, it just isn't something you should do.

    I would do it using a Union query. I would also add a column to tell which

    Select 'Inserted' as TableName, *
    From Inserted
    Union
    Select 'Deleted' as TableName, *
    From Deleted
    Union
    Select 'Carrier' as TableName, *
    From Carrier


    If you only want to return the records affected by the update then Join the Carrier table to either the inserted or deleted table, it doesn't matter which.

  8. #8
    Join Date
    Jul 2005
    Posts
    6
    Thanks Rawhide,

Posting Permissions

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