SQLite | Triggers | Dropping a Trigger

This article explains how to drop a trigger. A trigger is removed either explicitly or automatically when its associated table is dropped.

Dropping a Trigger

Use the DROP TRIGGER statement.

DROP TRIGGER trigger_name;

Before dropping the trigger, inspect it with .schema.

.schema
sqlite> .schema
CREATE TABLE product (id integer, name text);
CREATE TABLE history (user text, name text, sales integer);
CREATE TRIGGER updateproduct update of name on product
begin
update history set name = new.name where name = old.name;
end;
sqlite> 

Drop the updateproduct trigger.

drop trigger updateproduct;
sqlite> drop trigger updateproduct;
sqlite> 

Run .schema again to verify that it was removed.

.schema
sqlite> .schema
CREATE TABLE product (id integer, name text);
CREATE TABLE history (user text, name text, sales integer);
sqlite> 

The updateproduct trigger no longer appears.

Dropping the Table Associated with a Trigger

Dropping a table automatically drops its triggers.

Display the current tables and triggers with .schema.

.schema
.schema
CREATE TABLE product (id integer, name text);
CREATE TABLE history (user text, name text, sales integer);
CREATE TRIGGER updateproduct update of name on product
begin
update history set name = new.name where name = old.name;
end;
sqlite> 

If the trigger is missing after the previous example, recreate it from the displayed schema.

The updateproduct trigger belongs to the product table. Drop that table and run .schema again.

drop table product;
sqlite> drop table product;
sqlite> 
sqlite> .schema
CREATE TABLE history (user text, name text, sales integer);
sqlite> 

Dropping product also removed its updateproduct trigger.