Académique Documents
Professionnel Documents
Culture Documents
Databases: systems that manage a large collection of data. Users can perform queries & updates query: current DB state -> query answer update: current DB state -> new DB state Databases disallow updates that violate the constraints.
Active Databases
triggers
is
Active database support mechanisms that enable them to respond automatically to events that are taking place either inside or outside the database system itself. Database system augmented with rule handling Active approach to managing integrity constraints ECA rules: event, condition, action.
Triggers
A trigger is a named database object that is associated with a table, and that activates when a particular event occurs for the table.
Triggers are a special type of procedure that are fired automatically when an query is executed on a table. Triggers provide a powerful way of control how action queries modify the data in your database.
Triggers are a means of introducing specific reactions to particular events relevant to the database. Such events
are currently restricted to database specific operations (i.e. queries and updates) and operation calls.
The Event-Condition-Action (ECA) is a model for specifying active database rules. A rule in ECA model has three components:
1)
The event would be a database update operations, temporal events, or other kinds of external events. The condition determines whether the rule action should be executed. The action is a sequence of SQL statements, transactions, or an external program that will be automatically executed.
2)
3)
An Event-Condition-Action rule performs actions in response to events, given that a stated condition holds. An event in a database system can be the insertion of a new tuple. The condition can be a query. The action may be a relational table update. This behavior is called reactive functionality.
ECA rules
ON update BONUS_amount, IF update.amount > 100, THEN update EMP set rank = old. rank + 1 where emp_id = update.emp_id;
Triggering
triggering event
DB
triggered action
think of examples
Triggering Time before or after the triggering event (s), Triggering Event a change to the database that activates the trigger, Name of the table where the event is monitored, Specification of whether the trigger should fire for each row affected, or only once per SQL statement that caused the firing Action the trigger procedure (user defined function)
Trigger Syntax
CREATE TRIGGER trigger_name { BEFORE | AFTER } { INSERT | DELETE | UPDATE } [ OF columns ] ON table_name [ REFERENCING [ OLD AS var_to_old_row ] [ NEW AS var_to_new_row ] [ OLD TABLE AS var_to_old_table ] [ NEW TABLE AS var_to_new_table ] ] [ FOR EACH { ROW | STATEMENT } ] [ WHEN (condition) ] statements
BEFORE triggers are fired before the execution of a triggering statement. For example a before trigger can be used to take back up of data contained in a table before a particular batch of statements.
AFTER triggers execute the trigger action after the triggering statement is executed.
trigger_event indicates the kind of statement that activates the trigger. The trigger_event can be
one of the following: INSERT: The trigger is activated whenever a new row is inserted into the table; for example, through INSERT, LOAD DATA, and REPLACE statements. UPDATE: The trigger is activated whenever a row is modified; for example, through UPDATE statements. DELETE: The trigger is activated whenever a row is deleted from the table; for example, through DELETE and REPLACE statements.
A row trigger is fired every time when the triggering statement affects the table. If an UPDATE statement updates several rows of a table, a row trigger is fired one time for each row affected by the UPDATE statement. If a triggering statement affects no rows, a row trigger is not executed at all.
A statement trigger is fired once on behalf of the triggering statement, regardless of the number of rows affected by the triggering statement.
For example, even if a DELETE statement deletes several rows from a table, a statement-level DELETE trigger is fired only once.
Do not accept parameters or arguments. Cannot perform commit or rollback operations because they are part of the triggering SQL statement (only through autonomous transactions). Can cause mutating table errors, if they are poorly written.
Advantages of triggers
Disadvantages of triggers
You cannot have two triggers for a table that have the same activation time and activation event. The trigger cannot use statements that explicitly or implicitly begin or end a transaction such as START TRANSACTION, COMMIT, or ROLLBACK.
Triggers are difficult to use (if many of them).
It define relationships between the tables. These relationships enable to combine data from several tables for querying. This is accomplished through the use of keys, which are database fields used to uniquely identify specific records in a table. Relational database technology allows databases to be larger, faster, and more efficient. A relational DBS must be able to manage databases entirely through its relational capabilities.
Active object-oriented databases includes modeling the structure of objects, their passive behavior in the form of operations that can be performed on them, and their active behavior in the form of business rules.
An ADBMS is an DBMS as well. An ADBMS supports definition and management of ECA rules. Able to execute actions. Has well defined execution semantics. Support a programming environment.
Integrity management
Derived data maintenance Workflow management
Integrity Management
When using triggers to maintain referential integrity, declare the PRIMARY (or UNIQUE) KEY constraint in the parent table. Integrity is enforced by the system, either during transaction execution (immediate constraint) or at commit time (deferred constraint). Integrity rules express constraints that must be true in the DB.
A view is a query on the database; it may be virtual or materialized. View maintenance problem: changes in underlying tables. maintain data when
Two alternatives: refresh approach (recompute view from scratch) or incremental approach (compute only things that have changed). Rules can be used to support both, but incremental is much more complicated.
Workflow Management
The primary advantage to workflow management is improved efficiency within the business. It also makes it easier to track employee and machine performance. It serves to standardize working methods, ensuring that every employee working on the same level is performing the same function.
It allows the customer to feel completely involved in the entire process and capable of getting answers to important questions in a timely fashion.
Conclusion
Active database support mechanisms that enable them to respond automatically to events that are taking place either inside or outside the database system itself.
Triggers are a means of introducing specific reactions to particular events relevant to the database. Such events are currently restricted to database specific operations (i.e. queries and updates) and operation calls.
The whole study shows that ECA rules is a usable technology for various different application environments over semi-structured data. Applications for active databases: Integrity maintenance, Derived data maintenance, Workflow management
References
Active Rules in Database Systems - by Norman W Paton en.wikipedia.org/wiki/Active_database . cs.ulb.ac.be portal.acm.org www.activedbsoft.com www.informatik.uni www.encyclopedia.com it.toolbox.com www.highbeam.com www.patentstorm.us www.powells.com