From the course: Program Databases with Transact-SQL

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create a database trigger

Create a database trigger - SQL Server Tutorial

From the course: Program Databases with Transact-SQL

Start my 1-month free trial

Create a database trigger

- [Narrator] Database triggers are a special kind of stored procedure. Instead of running when they're manually executed, triggers automatically fire when a specific activity, occurs on the server. You can attach triggers to data manipulation events, such as insert, update, and delete commands, or you can have them fire when the database processes a data definition command, such as create or alter table. Let's see how triggers work by setting up a system that will automatically log changes to the colors table, in a new audit table. First, I'm going to create a table for the audit, I'll place it inside of the warehouse schema, and I'll call the table color audit, it's going to have three columns, the first column, Audit ID will be an integer value, it'll be the identity column, and it will be the primary key for the table, then we'll add a column for the color name, as well as a date time column called time added. So let's go ahead and create that color audit table, and now we can turn…

Contents