AFTER INSERT triggers execute after new rows successfully persist to table.
NEW values are finalized and read-only (no modification possible).
Perfect for logging, summary calculations, notifications, and cross-table updates.

Basic AFTER INSERT Syntax


NEW in AFTER INSERT
NEW = finalized row values (read-only).
OLD unavailable (no previous row existed).

Simple Audit Logging


Summary Table Updates


Multi-Table Logging


Department Statistics Update


Notification Trigger



Inventory Reordering



Cross-Reference Population



NEW Column Availability

AFTER INSERT

NEW

OLD

All columns

✓ (Read-only)

Complex Audit with JSON


Category Revenue Rollup


Permissions Required


Testing AFTER INSERT Trigger

Execution Flow

  1. INSERT statement executes
  2. Row written to table successfully
  3. AFTER INSERT triggers fire (alphabetical order)
  4. Secondary tables updated

Performance Considerations

Concern

Impact

Mitigation

Multi-table writes

High

Batch operations

Summary calculations

Medium

Indexes

External calls

Very High

Queue systems

Common Use Cases

  • Audit trail creation
  • Summary/aggregate table maintenance
  • Notification systems
  • Cache invalidation
  • Cross-table relationship updates

Important Notes

  • NEW values read-only after INSERT completes
  • Can update other tables (not triggering table)
  • Multiple AFTER INSERT triggers execute alphabetically
  • Failures roll back entire transaction

Production Pattern: Order Processing



Bulk Insert Optimization


Error Scenarios

-- If audit table full, entire INSERT fails

-- Transaction rollback includes original INSERT

-- Secondary table updates also rolled back

Key Points

  • AFTER INSERT fires post-successful row insertion
  • NEW read-only, contains final values
  • Perfect for logging and summary updates
  • Can affect other tables, not triggering table
  • Transactional: failures roll back everything
  • Alphabetical execution order