How To Create PostgreSQL PL/pgSQL Trigger Procedures
A trigger is a set of actions that are run automatically when a specified change operation (SQL INSERT, UPDATE, DELETE or TRUNCATE statement) is performed on a specified table. Triggers are useful for tasks such as enforcing business rules, validating input data, and keeping an audit trail. Uses for triggers : Enforce business rules Validate input data Generate a unique value for a newly-inserted row in a different file. Write to other files for audit trail purposes Query from other files for cross-referencing purposes Access system functions Replicate data to different files to achieve data consistency Benefits of using triggers in business : Faster application development. Because the database stores triggers, you do not have to code the trigger actions into each database application. Global enforcement of business rules. Define a trigger once and then reuse it for any application that uses the database. Easier maintenance. If a business policy changes, you need to...