ACTIVE DATABASES & TRIGGERS
| Source: Database |
Multiple triggers can be activated within a single statement at once. If the trigger is active, the condition section is executed first, followed by the action part if the stated condition is true.
In this case, the DBMS randomly executes each of the triggers. When an action phase of a trigger is executed, it might either activate other triggers or the same trigger that initiated the action. The term "recursive trigger" refers to a sort of trigger that triggers itself. Although the DBMS executes such trigger chains in a predetermined manner, it has an impact on the idea of comprehension.
Let’s Understand the concept more thoroughly...
ACTIVE DATABASES
An active database is one that has an event-driven structure, which is typically implemented in the process of Event Condition Action rules which can respond to events both inside and outside the database.
| Source: Active Databases |
An active database system (ADBS) monitors events of interest and, when they arise, initiates a prompt response.
It's commonly used for security monitoring, alerting, information gathering, and authorization.
ADVANTAGES OF ACTIVE DATABASE
CHARACTERISTICS OF ACTIVE DATABASE
- It has all of the principles of a traditional database, such as data modeling capabilities, query language, and so on.
- It includes all typical database tasks such as data definition, data manipulation, storage management, and so on.
- It detects the occurrence of events.
- It must be able to assess situations and carry out actions. This implies that rule execution must be implemented.
- It assists in the development and administration of ECA rules.
TRIGGERS
A trigger is a database administrator-defined procedure that is automatically invoked by the database management system (DBMS) in reaction to database changes (DBA). A database with a set of associated triggers is generally called an active database.
| Source: Triggers |
Different types of triggers are classified into three categories -
A. Level triggers-
Level trigger has two types i.e. Row Level Trigger and Statement Level Trigger that are explained below -
Row Level Trigger
A row-level trigger triggers once for each row affected by the triggering event. Row level trigger uses a FOR EACH ROW clause in its triggering statement always.
Data-related operations including data auditing and data validation derive from row-level triggers.
| Syntax for creating row level trigger |
2. Statement Level Trigger
Whenever a triggering event occurs on a database, a statement-level trigger is triggered, irrespective of how many rows are affected.
Key points to remember -
Statement level triggers are default triggers that can be created once a trigger is created without requiring use for each row statement.
Statement level trigger fires for only once for each triggering event.
It also fires once if no rows are impacted.
| Syntax of creating a statement-level trigger |
DEMO-
CODE:
OUTPUT:
B. Event Triggers -
Event triggers are categorized into three types that are DDL, DML and database triggers. Operations performed by them are listed below -
DDL triggers
SQL Server's DDL triggers are triggered by various data definition language (DDL) events such as Create, Alter, Drop, Grant, etc,. DDL triggers are only activated once the DDL statements that set them off have been executed.
INSTEAD OF triggers cannot be used with DDL triggers.
Events that affect local or global temporary tables and stored procedures do not activate DDL triggers.
DML triggers
![]() |
| Source: DML Triggers |
- DML triggers are a form of stored method that takes place automatically whenever a data manipulation language (DML) event occurs that affects the table or view specified in the trigger.
- INSERT, UPDATE, and DELETE statements are examples of DML events.
3. DATABASE triggers
- Database triggers are triggered by the execution of any database operation, such as LOGON, LOGOFF, SHUTDOWN, SERVERERROR, and so on.
To get the salary information:
C. Timing Triggers -
Before trigger
A Before Trigger is a sort of trigger which executes automatically before a specific operation on the table actually occurs.
Before triggers are used to validate data before it is accepted into the table and to evaluate values before they are deleted from the table.
After trigger
An after trigger is a sort of trigger that fires automatically after a specific action on the table.
After triggers are used to update data in a table after a change occurs.
ADVANTAGES
Some of the advantages of using MySQL triggers are listed below:
Trigger can assist us in automating data changes.
Triggers can provide a way to check the database's data integrity.
It is useful for identifying errors in database layers.
Facilitates data auditing.
It allows us to reuse queries that have already been written.
Plays a major role in the detection of database faults.
Triggers can be used to log an event and can also store the information on the table.
DISADVANTAGES
The disadvantages of using MySQL triggers are listed below:
Tends to increase the site's overhead expenses.
It only provides expanded validations; not all validations are available through SQL triggers.
If we activate the incorrect trigger by accident, we risk losing the original data.
It takes a long time to troubleshoot difficulties caused by triggers.
Even if there is a minor inaccuracy in the query, it can generate logical issues in the application.
USES OF TRIGGER
- To establish data consistency, duplicate data to separate files.
- It's useful for keeping track of the changes to a table.
- Triggers are used to perform automatic actions when another action is triggered.
- Enforces referential integrity, Synchronous replication of tables and Preventing invalid transactions.
By-
CS-A, Batch-1, Group SY4
Authors:
Anikka Pandey
Shreya Ambekar
Amey Joshi
Somesh Alkanthi
Aishwarya Kale
.png)
.png)

Fabulous ๐
ReplyDeleteAmazing!
ReplyDeleteEasy to read and implement.
Great work!!
ReplyDeleteA short and effective blog. Keep up the good work๐
ReplyDeleteGreat use of tables and images making it easy to understand
ReplyDeleteNice content
ReplyDeleteGreat Blog! Very informative and presentable. Keep it up.
ReplyDeleteAwesome Blog !!!
ReplyDeleteNice use of Examples
Great work !!
ReplyDeleteDetailed blog with nice illustrations
ReplyDeleteGreat Content!!!
ReplyDeleteWell done guys, content wise it looks good, keep it up
ReplyDeleteGreat team work๐๐ป
Informative
ReplyDeleteGreat Blog!!
ReplyDeletePrecise with good use of images. Felt interactive
ReplyDeleteGreat job! Keep publishing such good ones.
ReplyDelete