• About Us
    • Who We Are
    • Our Work
    • Our Clients
    • Our Partners
    • Our Blog
    • News & Events
    • Insights
  • Solutions

    Analytics & Data Management

    Big DataBusiness AnalyticsData IntegrationData Warehousing

    Digital Business Automation

    Advanced Case ManagementBusiness Rules ManagementBusiness Process ManagementRobotic Process Automation

    Connectivity & System Integration

    Agile IntegrationAPI ManagementEnterprise Service Bus

    Enterprise Content Management

    Content Capturing & ImagingEnterprise Content Management

    Enterprise Portal & Mobility

    Digital Customer ExperienceDigital Workplace

  • Industry Solutions

    • Banking >
    • Government >

    Digital Banking Transformation

    Business Process Management

    Business Rules Management

    Checks Collection & Clearing

    Counter Fraud Management

    Customer Due Diligence

    Customer Onboarding

    Daily Vouchers Management

    Debt Collections & Recovery

    Instant Payment Network Gateway

    Enterprise Content Management

    Enterprise Service Bus

    Smart Analytics

    Trade Finance Automation

    Digital Government Transformation

    Business Analytics

    Business Process Management

    Correspondence Management

    Documents & Records Management

    Enterprise Service Bus

    Pensions & Social Programs

    Social Collaboration Portal

    Strategy Management

    Utility Billing

  • Services
    • Cloud Apps & Microservices
    • IT Consultancy
    • Application Development
    • Testing Services
  • Careers
    • Careers Homepage
    • Get To Know Us
    • Engineering @ Sumerge
    • Our Culture
    • Benefits & Wellbeing
    • Job Openings
    • Graduate Programs
  • Contact Us
  • About Us
    • Who We Are
    • Our Work
    • Our Clients
    • Our Partners
    • Our Blog
    • News & Events
    • Insights
  • Solutions

    Analytics & Data Management

    Big DataBusiness AnalyticsData IntegrationData Warehousing

    Digital Business Automation

    Advanced Case ManagementBusiness Rules ManagementBusiness Process ManagementRobotic Process Automation

    Connectivity & System Integration

    Agile IntegrationAPI ManagementEnterprise Service Bus

    Enterprise Content Management

    Content Capturing & ImagingEnterprise Content Management

    Enterprise Portal & Mobility

    Digital Customer ExperienceDigital Workplace

  • Industry Solutions

    • Banking >
    • Government >

    Digital Banking Transformation

    Business Process Management

    Business Rules Management

    Checks Collection & Clearing

    Counter Fraud Management

    Customer Due Diligence

    Customer Onboarding

    Daily Vouchers Management

    Debt Collections & Recovery

    Instant Payment Network Gateway

    Enterprise Content Management

    Enterprise Service Bus

    Smart Analytics

    Trade Finance Automation

    Digital Government Transformation

    Business Analytics

    Business Process Management

    Correspondence Management

    Documents & Records Management

    Enterprise Service Bus

    Pensions & Social Programs

    Social Collaboration Portal

    Strategy Management

    Utility Billing

  • Services
    • Cloud Apps & Microservices
    • IT Consultancy
    • Application Development
    • Testing Services
  • Careers
    • Careers Homepage
    • Get To Know Us
    • Engineering @ Sumerge
    • Our Culture
    • Benefits & Wellbeing
    • Job Openings
    • Graduate Programs
  • Contact Us
Database Events & Triggers

Database Events & Triggers

  • Posted by Amr Soliman
  • On December 14, 2022

Every software engineer has a common goal in mind, to create and maintain a high-performance application. In order to achieve such a goal, the infrastructure of the application, the database, needs to be monitored regularly. Database monitoring involves the tracking of the database performance and resources. However, as you may have already guessed, database monitoring is quite time consuming and prone to human-made errors. That’s where database automation comes to the rescue.

 

Database automation is the use of already established functions to monitor and perform administrative tasks on the database automatically. Sounds great, right? How can this be done though? There are multiple database automation techniques which can be used nowadays. In this blog, we will be discussing two techniques of database automation in depth, Events and Triggers.

 

What are Triggers?

 

Triggers, as they may sound, are already coded procedures which are run just before or right after a specific action, INSERT-UPDATE-DELETE, occurs within the database. These procedures can include the modification or verification of incoming data, the calculation which needs to be performed, or the execution of further actions.

 

When can we use Triggers?

Let’s imagine the following scenario. We have a table called users which carries the basic user details (id, email, password, enabled). Keep in mind that the user has the authority to update any of these fields anytime. Now, we want to keep track of every time the user makes an update in a table named as ‘user_log’ for monitoring and performance purposes. That’s when we can use Triggers to accomplish this desired outcome. Since we would like to keep track of the update action “After” it’s done, this trigger is considered an after-update trigger.

 

The Triggers Implementation

• Create a trigger and give it a name
• Proceed to set the After-UPDATE condition, so it can be invoked once the action is taken by the user.
• Declare the default value for all to be “unchanged” to make it easier to check only the changed values.
• Proceed to use if statements to check which values were changed by the user. After that, we will use the INSERT command to log the changed values to a new record in the user_log table.

 

 

Making an update to the enabled value for the user with the ID 2.

 

 

After displaying the ‘user_log’ table, we will be able to find the below record which was automatically created after the update command has been executed with the updated values, while the un-updated ones are displayed as “unchanged”.

 

 

What are Events?

 

Events, also known as temporal triggers, are the actions run at certain time periods previously scheduled. Events are quite crucial for archiving data, and cleaning logs in the database.

 

When Can We Use Events?

Let’s recall the scenario mentioned in the triggers section above. This time, let’s envision that this system is used by thousands of users, keeping in mind that every time any of those users make an update to their user details, a record will be inserted in the ’user_log’ table since we implemented the triggers on the update action. You can imagine that it will only take some time for the ‘user_log’ table to be full and unable to accept any more entries. In a normal situation, we will need to manually delete the old records to free up some space, which brings us back to the time-consuming and the human-error issues. Thankfully, events can take care of such a scenario and delete the records automatically after a pre-scheduled time has passed, in this case we will set it to 1 month.

 

Events Implementation

• Create our event and give it a name.
• Set the scheduled time to be after 1 month
• The SQL command to be used after the scheduled time has passed is the DELETE command from the user_log table.

 

 

Take note that once the event has been created, it will run instantly, then it will be repeated after the scheduled time has passed, in this case 1 month. Therefore, there is no need to run it once again.

 

After displaying the user_log table, we can conclude that the event ran successfully and the records were deleted, leaving the table empty for the new records.

 

 

The Takeaways

Triggers can be used to automatically run certain a pre-defined set of action before or after the INSERT, UPDATE, DELETE SQL commands for verification of modification purposes, while events can be used to automatically run a pre-defined set of action at a scheduled time for data archive and log cleansing purposes.

 

You can find other examples on the usage of triggers and events from the below links:

 

https://dev.mysql.com/doc/refman/5.6/en/create-event.html

https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

 
Recent Blog Posts
  • Event Streaming: Enhancing Efficiency in Banking 
  • Your Guide To Integration Modernization
  • APIs: Transforming Chaos into Order
  • Event Streaming Simplified
  • Unlocking the Power of Spring Data JPA
Categories
  • Careers
  • Webinars
  • blog
    • Educational
  • Technology & Business
    • Digital Business Automation
    • /Modernization & Cloud Native Apps
    • Banking
    • Agile Integration
  • Software Engineering
    • Application Servers
    • Application Testing
    • Business Analysis
    • Frontend
    • Microservices
    • Uncategorized
  • Blog Posts
  • News & Events
  • Featured

Sumerge x IBM Roundtable Event Saudi Arabia

Previous thumb

Top Four Integration Modernization Best Practices

Next thumb
Scroll
Follow us

Significant change, positive impact and passion are our fuel. We have a unique culture reflecting the way we think and act. A culture that encourages freedom and responsibility, high performance, customer centricity and innovation.

Global Locations

Egypt

Saudi Arabia

United States

About us

Who We Are
Our Work
Our Clients
Careers
News & Events
Insights

Services

Cloud Apps & Microservices
Application Development
Consultancy
Testing Services

Solutions

Analytics & Data Management
Business Process Automation
Agile Integration
Enterprise Content Management
Enterprise Portal & Mobility

Industries

Banking
Government

Latest Blogs
  • Design Patterns
    August 23, 2022
  • Hybrid Workplace: A Match Made in Post-Pandemic Era
    March 22, 2022
Copyright Ⓒ 2024 Sumerge. All rights reserved.
  • Blog
  • |
  • Support
  • |
  • Contact Us
  • |
  • Privacy Policy
Sumerge
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}

     

    Book A Free Consultation Session