• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Triggers on views

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Triggers on views

    Just had a brilliant issue where a view was dropped and recreated. It then no longer worked for update - no one could figure out how it had ever worked!

    Turned out to be a trigger on a view! A very sneaky way of obfuscation if ever I saw one.

    I thought I had seen it all - clearly not.

    #2
    Originally posted by BrilloPad View Post
    Just had a brilliant issue where a view was dropped and recreated. It then no longer worked for update - no one could figure out how it had ever worked!

    Turned out to be a trigger on a view! A very sneaky way of obfuscation if ever I saw one.

    I thought I had seen it all - clearly not.
    Had this a couple of times and now triggers are one of the things on my checklist of possible things to check.

    It's a shame that they never became more popular as they are good for maintaining business logic in the database structure which the RDBMS might not be able to cope with.
    Coffee's for closers

    Comment


      #3
      Originally posted by BrilloPad View Post
      Just had a brilliant issue where a view was dropped and recreated. It then no longer worked for update - no one could figure out how it had ever worked!

      Turned out to be a trigger on a view! A very sneaky way of obfuscation if ever I saw one.

      I thought I had seen it all - clearly not.
      Don't understand your post. There are rules when you can use an UPDATE statement on a view e.g. can't contain an aggregated field. If you are allowed to UPDATE a view, surely this just updates the base table so where does the trigger come in?



      p.s. I passed a 'rigourous' 2 hour on-line advanced SQL test a while back and always interested in this type of thing!
      Last edited by oscarose; 4 July 2012, 08:51. Reason: addition
      one day at a time

      Comment


        #4
        Originally posted by oscarose View Post
        Don't understand your post. There are rules when you can use an UPDATE statement on a view e.g. can't contain an aggregated field. If you are allowed to UPDATE a view, surely this just updates the base table so where does the trigger come in?



        p.s. I passed a 'rigourous' 2 hour on-line advanced SQL test a while back and always interested in this type of thing!
        You can create a trigger on a view in the same way you create a trigger on a table.
        Any DML performed through the view fires the trigger. If the view is dropped and recreated then the trigger is lost.
        Coffee's for closers

        Comment


          #5
          Originally posted by Spacecadet View Post
          You can create a trigger on a view in the same way you create a trigger on a table.
          Any DML performed through the view fires the trigger. If the view is dropped and recreated then the trigger is lost.
          Triggers on views sound dodgy to me. As we all know, views are primarily for hiding data complexity, summarising data and security. IMO, the trigger should be on the underlying table.

          As always though, there's probably a valid reason and requirement to have the trigger on the view for a particular business reason.
          Last edited by oscarose; 4 July 2012, 09:56. Reason: spelling
          one day at a time

          Comment


            #6
            Originally posted by oscarose View Post
            Triggers on views sound dodgy to me. As we all know, views are primarily for hiding data complexity, summarising data and security. IMO, the trigger should be on the underlying table.

            As always though, there's probably a valid reason and requirement to have the trigger on the view for a particular business reason.
            Not something I would do myself and I even avoid triggers on tables, the main reason being that they are not widely used and I don't like leaving suprises for other people.
            Coffee's for closers

            Comment


              #7
              Originally posted by Spacecadet View Post
              Not something I would do myself and I even avoid triggers on tables, the main reason being that they are not widely used and I don't like leaving suprises for other people.
              Is this platform specific?

              We love triggers on the iSeries...
              ‎"See, you think I give a tulip. Wrong. In fact, while you talk, I'm thinking; How can I give less of a tulip? That's why I look interested."

              Comment


                #8
                Originally posted by Spacecadet View Post
                Not something I would do myself and I even avoid triggers on tables, the main reason being that they are not widely used and I don't like leaving suprises for other people.
                Triggers are useful for enforcing business logic - just another tool in the bag.
                one day at a time

                Comment


                  #9
                  Originally posted by oscarose View Post
                  Triggers are useful for enforcing business logic - just another tool in the bag.
                  I know

                  Originally posted by Spacecadet View Post
                  they are good for maintaining business logic
                  Coffee's for closers

                  Comment


                    #10
                    Originally posted by oscarose View Post
                    Triggers on views sound dodgy to me. As we all know, views are primarily for hiding data complexity, summarising data and security. IMO, the trigger should be on the underlying table.

                    As always though, there's probably a valid reason and requirement to have the trigger on the view for a particular business reason.
                    CREATE TRIGGER [dbo].[my_trigger_name] ON [dbo].[my_view_name]

                    INSTEAD OF UPDATE, INSERT
                    AS
                    BEGIN
                    .
                    .
                    .
                    END

                    THERE IS NO VALID REASON!

                    Its just obfuscation.

                    Comment

                    Working...
                    X