From the course: Complete Guide to Advanced SQL Server
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Create a database trigger - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Create a database trigger
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 ColorAudit. It's going to have three columns. The first column AuditID will be an integer value. It'll be the identity column. And it'll be the primary key for the table. Then we'll add a column for the ColorName, as well as a datetime column called TimeAdded. So let's go ahead and create that ColorAudit table. And now we can turn our attention to creating…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Write and execute a stored procedure7m 43s
-
(Locked)
Stored procedure input parameters7m 38s
-
(Locked)
Stored procedure output parameters3m 38s
-
(Locked)
Create a database trigger3m 37s
-
(Locked)
Challenge: Use function in a stored procedure1m 25s
-
(Locked)
Solution: Use function in a stored procedure7m 43s
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-