[RESOLVED] An alternative to SQL triggers
Results 1 to 6 of 6

Thread: [RESOLVED] An alternative to SQL triggers

  1. #1
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    461

    resolved [RESOLVED] An alternative to SQL triggers

    I was sitting doing SQL triggers, but I was thinking they might be a bit taxing on a database, is there an alternative?
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,518
    Depends on how you're using them. Depending on the DBMS triggers might be used internally anyway for various things, such as constraints, partitioning, or updateable views; its developers would be working to make them work well. Conversely, that means you might be trying to use triggers to reimplement a feature that's already present.
    Or you have a lot of stuff that needs to get done in a lot of places. This may be a symptom indicating a restructuring of the scheme is in order. If the schema is fine, then the goal you're trying to meet with the triggers might be consolidated into a stored procedure.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,855
    A trigger may be more efficient than having your application code do one or more additional queries, since the trigger is more or less compiled once then used many time (possibly depending on the DBMS?). That being said, I seem to only use them when trying to put a quick band-aid on something where it was easier to take care of the needed DB changes than changing a bunch of legacy (spaghetti) code.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    461
    Well the idea is to display lets call it "events" set on a particular date for example, a social function is scheduled to start at 9pm on 08/10/2017 and finish at 11pm, once the event is complete it would automatically delete at say 11:01pm for example
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

  5. #5
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,855
    Hmm...I'd be more inclined to just limit what gets displayed in my SQL "where" clause, rather than deleting data, e.g.:
    Code:
    . . . WHERE event.end_time > NOW() . . .
    Then you still have all the event data if you ever want to do anything else with it.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  6. #6
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    461
    Quote Originally Posted by NogDog View Post
    Hmm...I'd be more inclined to just limit what gets displayed in my SQL "where" clause, rather than deleting data, e.g.:
    Code:
    . . . WHERE event.end_time > NOW() . . .
    Then you still have all the event data if you ever want to do anything else with it.
    Ah that would make more sense I guess
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Fresh start
    Current date 14/10/17
    Finish date "should be" 14/04/18

    Vote on your preferred indentation method

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •