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. can I trust Triggers?

can I trust Triggers?

Scheduled Pinned Locked Moved Database
announcementcomtutorialquestion
7 Posts 5 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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim

    Technology News @ www.JassimRahma.com

    T L J 3 Replies Last reply
    0
    • J Jassim Rahma

      Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim

      Technology News @ www.JassimRahma.com

      T Offline
      T Offline
      thatraja
      wrote on last edited by
      #2

      For logging purpose, Trigger is fine. Personally I prefer Stored procedure because you can't control the Trigger. And Trigger Disadvantages[^]

      thatraja

      Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute

      B 1 Reply Last reply
      0
      • J Jassim Rahma

        Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim

        Technology News @ www.JassimRahma.com

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

        Jassim Rahma wrote:

        my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table.

        Can be done both ways. Triggers *could* be harder to debug though. I cannot recommend anything, as that would depend on the requirements of the audit-trail. How does your "event log table" look, and what are you planning on doing with it?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • T thatraja

          For logging purpose, Trigger is fine. Personally I prefer Stored procedure because you can't control the Trigger. And Trigger Disadvantages[^]

          thatraja

          Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Your link shows very important information. And from that information, I conclude that it may be a bad decision to use them for logging purposes: in a transaction rollback, also the trigger actions will be rolled back. I.e. when you log by inserting into a table, that will be rolled back, too!

          T 1 Reply Last reply
          0
          • J Jassim Rahma

            Hi, I am currently using stored procedures to do an action after my INSERT, UPDATE or DELETE. I just wanted to ask for your advise.. do you recommend to continue using the stored procedures or start using triggers? my simple example is an event-log table... I insert a row in this table if a row was inserted in employees table. Thanks, Jassim

            Technology News @ www.JassimRahma.com

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Jassim Rahma wrote:

            or start using triggers?

            As with anything it depends on the usage.

            Jassim Rahma wrote:

            my simple example is an event-log table...

            Might note that in my experience doing this is often driven by the need for audit logging and it is seldom sufficient as it ignores user, reason and fails to allow deletions to be handled well.

            J 1 Reply Last reply
            0
            • B Bernhard Hiller

              Your link shows very important information. And from that information, I conclude that it may be a bad decision to use them for logging purposes: in a transaction rollback, also the trigger actions will be rolled back. I.e. when you log by inserting into a table, that will be rolled back, too!

              T Offline
              T Offline
              thatraja
              wrote on last edited by
              #6

              Sorry for the delay. For beginners(yes he is), Triggers not suggestable. We can't control that. As Eddy said, we can't dubug too. Personally I use Stored procedure instead of trigger. But I rarely use triggers for tasks such as audit trail(During Login/Logout).

              thatraja

              Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute

              1 Reply Last reply
              0
              • J jschell

                Jassim Rahma wrote:

                or start using triggers?

                As with anything it depends on the usage.

                Jassim Rahma wrote:

                my simple example is an event-log table...

                Might note that in my experience doing this is often driven by the need for audit logging and it is seldom sufficient as it ignores user, reason and fails to allow deletions to be handled well.

                J Offline
                J Offline
                Jassim Rahma
                wrote on last edited by
                #7

                so in this case you pefer to do it through SPs?

                Technology News @ www.JassimRahma.com

                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