Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you list all triggers in a MySQL database?

Tags:

mysql

triggers

People also ask

How do I get a list of triggers in current database?

You can use the sys. triggers system catalog view to get a list of all triggers in a database. This view returns all triggers with a type of TR (SQL DML trigger) or TA (Assembly (CLR) DML trigger). It returns both DML trigger names and DDL trigger names (unlike the next option, which only returns DML triggers).

Which command will return a list of triggers?

You can use the sys. triggers catalog view to return a list of triggers in a database in SQL Server. This view contains a row for each object that is a trigger, with a type of TR or TA.


The command for listing all triggers is:

show triggers;

or you can access the INFORMATION_SCHEMA table directly by:

select trigger_schema, trigger_name, action_statement
from information_schema.triggers
  • You can do this from version 5.0.10 onwards.
  • More information about the TRIGGERS table is here.

I hope following code will give you more information.

select * from information_schema.triggers where 
information_schema.triggers.trigger_schema like '%your_db_name%'

This will give you total 22 Columns in MySQL version: 5.5.27 and Above

TRIGGER_CATALOG 
TRIGGER_SCHEMA
TRIGGER_NAME
EVENT_MANIPULATION
EVENT_OBJECT_CATALOG
EVENT_OBJECT_SCHEMA 
EVENT_OBJECT_TABLE
ACTION_ORDER
ACTION_CONDITION
ACTION_STATEMENT
ACTION_ORIENTATION
ACTION_TIMING
ACTION_REFERENCE_OLD_TABLE
ACTION_REFERENCE_NEW_TABLE
ACTION_REFERENCE_OLD_ROW
ACTION_REFERENCE_NEW_ROW
CREATED 
SQL_MODE
DEFINER 
CHARACTER_SET_CLIENT
COLLATION_CONNECTION
DATABASE_COLLATION

You can use below to find a particular trigger definition.

SHOW TRIGGERS LIKE '%trigger_name%'\G

or the below to show all the triggers in the database. It will work for MySQL 5.0 and above.

SHOW TRIGGERS\G

For showing a particular trigger in a particular schema you can try the following:

select * from information_schema.triggers where 
information_schema.triggers.trigger_name like '%trigger_name%' and 
information_schema.triggers.trigger_schema like '%data_base_name%'

You can use MySQL Workbench: Connect to the MySQL Server Select DB

  • tables
  • on the table name line click the edit icon (looks like a work tool)
  • in the table edit window - Click the tab "Triggers"
  • on the Triggers list click th eTrigger name to get its source code