The Hidden Trigger

  • I hate triggers as much as tailgaters! When I first encountered them I felt they were really useful However ten years ago I ended up supporting a product that had been ported from a mainframe application. It soon became apparent that the person who ported the database had little understanding of database design and zero of topics such as normalisation. He had also added a lot of triggers that were undocumented. Added to this there was a web based front end (run over an intranet) where the underlying software did not have simple checks coded correctly. I used to spend days each month sorting out the data before the production of data for a SAP application. Raising the issues got nowhere as the implementers were favoured employees! I hate triggers!!!

  • manie (4/18/2016)


    roger.plowman (4/18/2016)


    Personally, I use three triggers on *almost every single table*--BUT 😀

    I only use them to create an audit log of insertions, deletions, updates and updates where I have to save the old value.

    That way I only have to pay attention to them when:

    1) I create them (using a template to make it consistent)

    2) An audit logging need changes (tighten/loosen requirements)

    3) I change the table structure (either deleting or renaming fields the triggers use)

    Doing it this way I find the only trigger I really have to worry much about is the update trigger -- and then only for reason #3. The Insert/Delete triggers pretty much take care of themselves.

    Limiting trigger use to this purpose moots trigger opacity.

    KISS -- Not Just A Pretty Acronym :hehe:

    Thanks Roger, This is exactly what I use them for and it is really handy with audit logging.

    I use them for auditing also. And you have less duplicated data to sort thru.

  • Well, I started on Sql Server 4.21 back when there was no DRI (declarative referential integrity) nor table checks so triggers were the only way to go as a single location for validation of a DML statement. Even then I despised them.

    Usually, I am able to replace most triggers by implementing foreign keys, checks, and filtered unique constraints. But still there are about 5% of the tables in any application that "require" triggers. For example, when using cascade deletes, only one downward delete path is allowed so the other path may need an instead of trigger to "manually" delete a referenced row before deleting itself.

  • mjh 45389 (4/20/2016)


    I hate triggers as much as tailgaters! When I first encountered them I felt they were really useful However ten years ago I ended up supporting a product that had been ported from a mainframe application. It soon became apparent that the person who ported the database had little understanding of database design and zero of topics such as normalisation. He had also added a lot of triggers that were undocumented. Added to this there was a web based front end (run over an intranet) where the underlying software did not have simple checks coded correctly. I used to spend days each month sorting out the data before the production of data for a SAP application. Raising the issues got nowhere as the implementers were favoured employees! I hate triggers!!!

    Hate is a very strong word my friend. You cannot want to hate triggers because some guy made bad choices or created bad triggers.:w00t::w00t::w00t::w00t:

    Manie Verster
    Developer
    Johannesburg
    South Africa

    I am happy because I choose to be happy.
    I just love my job!!!

  • I should have said dislike although I will keep hate for tailgaters! Why? Before I had to give up motorcycling some lowlife tailgater punted me down some roadworks!!!

  • Triggers are no more hidden than (for example) FKs, cascading FKs, computed columns, or even views and functions (in some cases).

    While I feel the angst the some developers feel when they miss something like triggers when troubleshooting, it IS one of those many things that you need to be aware of and check for... just like any of the other "hidden" functionality.

    As to triggers themselves, I agree with what many others have stated. They are a tool and they have their place and, like any other programming tool, they can be well written or not. As for extra stuff in SSMS to identify when a trigger might be in play, I'd rather not see such a thing because there's already a very easy way to check for triggers in the Object Explorer and I'm opposed to the additional screen clutter that it may impose.

    If you want to talk about something "hidden", ask the question about why MS separated functions in the Object Explorer into two different categories instead of 3 or, better yet, why they didn't simply use one category to make functions really easy to lookup and have a simple marker as to the function type.

    If you wanted to add some useful screen eye-candy, make it so that tables that have triggers, views that call views and functions that call functions, tables, or views, etc, etc, are different color to alert you that you may actually have to use the "Dependencies" tool, which you should actually be doing in the first place when troubleshooting a problem (despite the fact that it sometimes misses things if the objects were built in the wrong order).

    Heh... with that thought in mind, leave things the way they are and have folks learn to use the tools that already exist that will help you discover such things during troubleshooting efforts. On that note, I'll also say that it would be nice if they categorized (with text labels instead of nearly identical tiny icons) things in the "Dependencies" display a little better.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • mjh 45389 (4/20/2016)


    I hate triggers as much as tailgaters!

    I love tailgaters. It's easy to know who to sue when you need to stop short. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • mjh 45389 (4/20/2016)


    I hate triggers as much as tailgaters! When I first encountered them I felt they were really useful However ten years ago I ended up supporting a product that had been ported from a mainframe application. It soon became apparent that the person who ported the database had little understanding of database design and zero of topics such as normalisation. He had also added a lot of triggers that were undocumented. Added to this there was a web based front end (run over an intranet) where the underlying software did not have simple checks coded correctly. I used to spend days each month sorting out the data before the production of data for a SAP application. Raising the issues got nowhere as the implementers were favoured employees! I hate triggers!!!

    So... just to clarify that's... one 'NO' vote for triggers?:-)

  • Jeff Moden (4/21/2016)


    Triggers are no more hidden than (for example) FKs, cascading FKs, computed columns, or even views and functions (in some cases).

    ...

    If you want to talk about something "hidden", ask the question about why MS separated functions in the Object Explorer into two different categories instead of 3 or, better yet, why they didn't simply use one category to make functions really easy to lookup and have a simple marker as to the function type.

    ...

    Heh... with that thought in mind, leave things the way they are and have folks learn to use the tools that already exist that will help you discover such things during troubleshooting efforts. On that note, I'll also say that it would be nice if they categorized (with text labels instead of nearly identical tiny icons) things in the "Dependencies" display a little better.

    Yes, come to think of it I probably have more complaints about linked server abuse than triggers. It would be useful to have an efficient dependency view for them to help you with your analysis. Scanning syscomments when you don't have source control isn't the end of the world but...

  • I have just been called out on the way I was looking at someone who attempted to tell me what a trigger was "...SQL Server, the world where I come from..." as though I knew nothing of SQL Server. I have a lot to learn but his description scared me for being so wrong. Even some Business Analysts said afterwards that it sounded wrong. It is all OK though as he is a Technical Architect. 😀

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Gary Varga (4/21/2016)


    I have just been called out on the way I was looking at someone who attempted to tell me what a trigger was "...SQL Server, the world where I come from..." as though I knew nothing of SQL Server. I have a lot to learn but his description scared me for being so wrong. Even some Business Analysts said afterwards that it sounded wrong. It is all OK though as he is a Technical Architect. 😀

    What was the description given?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • mjh 45389 (4/21/2016)


    I should have said dislike although I will keep hate for tailgaters! Why? Before I had to give up motorcycling some lowlife tailgater punted me down some roadworks!!!

    Ah... being on a motorcycle definitely makes it a whole lot different. I don't like even when it's another motorcycle, which is why I don't ride with groups.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (4/21/2016)


    Gary Varga (4/21/2016)


    I have just been called out on the way I was looking at someone who attempted to tell me what a trigger was "...SQL Server, the world where I come from..." as though I knew nothing of SQL Server. I have a lot to learn but his description scared me for being so wrong. Even some Business Analysts said afterwards that it sounded wrong. It is all OK though as he is a Technical Architect. 😀

    What was the description given?

    He was talking about the persistence of the event (like it was a message queue) and querying when it would be removed (like a temporary event subscription that applications - not systems - might have).

    It may have been his communication skills at this point but I did not recognise his description of triggers as being such. Even an incorrect one.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Gary Varga (4/25/2016)


    Jeff Moden (4/21/2016)


    Gary Varga (4/21/2016)


    I have just been called out on the way I was looking at someone who attempted to tell me what a trigger was "...SQL Server, the world where I come from..." as though I knew nothing of SQL Server. I have a lot to learn but his description scared me for being so wrong. Even some Business Analysts said afterwards that it sounded wrong. It is all OK though as he is a Technical Architect. 😀

    What was the description given?

    He was talking about the persistence of the event (like it was a message queue) and querying when it would be removed (like a temporary event subscription that applications - not systems - might have).

    It may have been his communication skills at this point but I did not recognise his description of triggers as being such. Even an incorrect one.

    You should ask him what the first two words of the code to create a trigger are. 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (4/25/2016)


    Gary Varga (4/25/2016)


    Jeff Moden (4/21/2016)


    Gary Varga (4/21/2016)


    I have just been called out on the way I was looking at someone who attempted to tell me what a trigger was "...SQL Server, the world where I come from..." as though I knew nothing of SQL Server. I have a lot to learn but his description scared me for being so wrong. Even some Business Analysts said afterwards that it sounded wrong. It is all OK though as he is a Technical Architect. 😀

    What was the description given?

    He was talking about the persistence of the event (like it was a message queue) and querying when it would be removed (like a temporary event subscription that applications - not systems - might have).

    It may have been his communication skills at this point but I did not recognise his description of triggers as being such. Even an incorrect one.

    You should ask him what the first two words of the code to create a trigger are. 😛

    Someone else? :Whistling:

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

Viewing 15 posts - 31 through 45 (of 51 total)

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