Administration

SQL CREATE TRIGGER

Run database logic in response to table events; trigger syntax varies substantially.

Availability: Common SQL with references for SQL standard, MySQL/MariaDB, PostgreSQL, SQL Server, SQLite and Oracle Database; syntax and feature support vary by engine and version.中文

Syntax

CREATE TRIGGER trigger_name ... ON table_name ...

Examples

Run database logic in response to table events; trigger syntax varies substantially.

-- See the target database reference before authoring triggers

SQLite-oriented example; consult the relevant dialect manual.

-- See the target database reference before authoring triggers

Parameters, options and clauses

Option / clauseDescription
EXPLAINShow the optimizer's planned execution strategy.
ANALYZESome engines execute the statement and report actual statistics; this can run the query.
FORMATChoose plan output format where supported.
Catalog / information schemaInspect objects and definitions through system metadata.
Dialect / versionCheck the linked database manual for vendor-specific behaviour.

Dialect references

Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory