CockroachDB Videos
← Back to all videos

What are database triggers? | Distributed Functions in CockroachDB

2025-04-02

Demos & Tutorials

Description

A trigger executes a function when one or more specified SQL operations is performed on a table. The executed function is called a trigger function and is written in PL/pgSQL. Triggers respond to data changes by adding logic within the database, rather than in an application. They can be used to modify data before it is inserted, maintain data consistency across rows or tables, or record an update to a row. Want to learn more about Triggers in CockroachDB? In this video, Cockroach Labs Technical Evangelist Rob Reid walks through how CockroachDB triggers simplify automation, enforce data consistency, and enhance efficiency by performing actions directly within the database. This video covers trigger functions, before and after triggers, and provides real-world examples, helping you effortlessly manage complex database operations. Want to learn more about triggers? Read our docs at https://cockroa.ch/3XV18IU What are database triggers? | Distributed Functions in CockroachDB 0:00 Why Use Database Triggers in CockroachDB? 0:27 Automating Actions Within CockroachDB 0:47 Trigger Types: Inserts, Updates, Deletes, Truncates 1:04 Setting Up Demo Tables 1:19 Creating Trigger Functions 1:56 Demo: Insert Trigger for Stock Management 2:52 Demo: Before Insert Trigger for Automated Data Population 3:26 Creating Complex Trigger Functions 4:25 Demonstrating Before Insert Triggers with Vectors 4:36 Summary: Benefits of Using Triggers in CockroachDB