Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Update trigger.

Update trigger.

Scheduled Pinned Locked Moved Database
databasequestionannouncement
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Septimus Hedgehog
    wrote on last edited by
    #1

    Chaps, I can't seem to find a definitive answer so maybe you can advise. Here's the scenario. Let's say I have an update trigger on a table. If I have statement like (rough syntax) update mytable set x = 0 where somecolumn > 293 and it updates, say, 300 records. Would an update trigger occur on every row updated or just once for the batch of updates, as it were? A long time back something I read/misread gave me the impression that some sql statements call the trigger for each row affected and another only does it once but I'm not sure what's fact and what's fiction.

    If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

    Richard DeemingR 1 Reply Last reply
    0
    • S Septimus Hedgehog

      Chaps, I can't seem to find a definitive answer so maybe you can advise. Here's the scenario. Let's say I have an update trigger on a table. If I have statement like (rough syntax) update mytable set x = 0 where somecolumn > 293 and it updates, say, 300 records. Would an update trigger occur on every row updated or just once for the batch of updates, as it were? A long time back something I read/misread gave me the impression that some sql statements call the trigger for each row affected and another only does it once but I'm not sure what's fact and what's fiction.

      If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      The trigger will file once for each statement. You should always write your triggers with the assumption that the inserted and deleted virtual tables will contain multiple rows.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S L 2 Replies Last reply
      0
      • Richard DeemingR Richard Deeming

        The trigger will file once for each statement. You should always write your triggers with the assumption that the inserted and deleted virtual tables will contain multiple rows.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        Septimus Hedgehog
        wrote on last edited by
        #3

        Richard, thanks for that. I need to schedule some time to look into them. I know they're basically simple concepts but it's in the doing that you understand them.

        If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

        M 1 Reply Last reply
        0
        • S Septimus Hedgehog

          Richard, thanks for that. I need to schedule some time to look into them. I know they're basically simple concepts but it's in the doing that you understand them.

          If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Triggers spit are a support nightmare, especially for a new developer. If you break a trigger (changing/removing a field) it can be extremely difficult for support to identify the problem (it can be bloody difficult for the silly bastard who wrote the trigger). We do use the horrible things but only for audit purposes NEVER to implement business logic, that lives in a stored proc that does what it is told when it is told and everyone knows where to find it.

          Never underestimate the power of human stupidity RAH

          S 1 Reply Last reply
          0
          • M Mycroft Holmes

            Triggers spit are a support nightmare, especially for a new developer. If you break a trigger (changing/removing a field) it can be extremely difficult for support to identify the problem (it can be bloody difficult for the silly bastard who wrote the trigger). We do use the horrible things but only for audit purposes NEVER to implement business logic, that lives in a stored proc that does what it is told when it is told and everyone knows where to find it.

            Never underestimate the power of human stupidity RAH

            S Offline
            S Offline
            Septimus Hedgehog
            wrote on last edited by
            #5

            Mycroft Holmes wrote:

            that lives in a stored proc that does what it is told when it is told and everyone knows where to find it.

            I wish our database at work was so obliging and obedient. :( In a previous job I remember problems with a trigger when looking for differences in the before and after images. I never worked on a more convuluted POS in my life. It was the kind of trigger that had an unwritten rota as to which mug of the month got as a prize.

            If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

            M 1 Reply Last reply
            0
            • S Septimus Hedgehog

              Mycroft Holmes wrote:

              that lives in a stored proc that does what it is told when it is told and everyone knows where to find it.

              I wish our database at work was so obliging and obedient. :( In a previous job I remember problems with a trigger when looking for differences in the before and after images. I never worked on a more convuluted POS in my life. It was the kind of trigger that had an unwritten rota as to which mug of the month got as a prize.

              If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              I dictate the standards on our DBs (mostly) so triggers and underscores struggle to survive and are hunted down and eliminated whenever I get really bored. This does tend to piss off the offending Dev who ignored the conventions. So today they ganged up on me and we will move to MVC instead of WPF for next years crop of apps- bastards!

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                The trigger will file once for each statement. You should always write your triggers with the assumption that the inserted and deleted virtual tables will contain multiple rows.


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Richard Deeming wrote:

                inserted

                Richard Deeming wrote:

                deleted

                Brings back old memories. A stupid bugger rejected me in an interview when I could't answer the question "what are magic tables?". I knew these tables and how to use them, it's just that he expected me to know that they're called magic tables (even after a decade, I haven't heard anyone else calling them by that name).

                Richard DeemingR 1 Reply Last reply
                0
                • L Lost User

                  Richard Deeming wrote:

                  inserted

                  Richard Deeming wrote:

                  deleted

                  Brings back old memories. A stupid bugger rejected me in an interview when I could't answer the question "what are magic tables?". I knew these tables and how to use them, it's just that he expected me to know that they're called magic tables (even after a decade, I haven't heard anyone else calling them by that name).

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  Well, by the highly scientific method of Google-fighting:

                  • sql trigger magic tables[^]: 413,000 results;
                  • sql trigger virtual tables[^]: 1,680,000 results;

                  your interviewer was an idiot. :)


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups