View triggers

  • hi, could somebody help please?

     

    i am fairly new to sql and have a project I am working on we’re I need to insert data to a linked server table from a view in my database.

    i have managed to insert the data but I would like to create a trigger or replicate my view results in the table so that when new record are added it will automatically push the results from my view to the table.

    how can I go about this any help would be appreciated.

    thanks in advance

  • A view is just a query, not a table (except in the case of indexed views, but you can't add data to them directly). No data is stored in a view. So, even if you use a view as a mask in front of  a table, the INSERT statement is not adding data to the view. It's adding data to the table. You shouldn't need a trigger to move the data from the view (where it isn't actually stored) to the table. If your testing is showing something else, then something else is going on.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Quite right.  If you wanted to use a trigger, you'd have to put a trigger(s) on the table(s) used within the view, not on the view itself.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Your best bet imho, is to replicate the table which is being updated

Viewing 4 posts - 1 through 3 (of 3 total)

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