There are numerous reasons for using stored procedures and triggers. Here are some of them:
• Provide central validation: We can enforce conditions on table updates in one place,
independent of our client applications. If the conditions need to change, they change in
one place only.
• Track changes: We can use a trigger to create an audit trail, writing to another table
when rows in a table are updated. This could record the user who made the change, the
time, the date, and perhaps even the data that changed.
• Enhance security: By using the PostgreSQL current_user variable, we can enforce our
own security.
• Defer deletions: We could use a trigger to mark rows for deletion at a later date, rather
than deleting them when an application tries to.
• Provide a mapping for clients: We can use triggers and stored procedures to create a
simpler, single-table version of some of our data that can be updated more easily by our
users. For example, we could create a table and link it to Microsoft Excel. As rows in this
table are updated, we can update rows in the “real” tables, which might have a more
complex structure.
No comments:
Post a Comment