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 trigger to print a message - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Create a trigger to print a message
Using an AFTER trigger, we can return a custom message to the end user when new data is added into a table. To set this up, I'm going to make sure that I'm using the KinetEcoTRG database and we'll create a new table called dbo.Products. This table will have two different columns, one called productID and the other one called productName. And then, so that we can see what the default message window looks like before we add in a trigger, I'm going to add in a single product for the nine volt battery into the table. Let's execute all of these commands to create the table, and we'll see that default message here. It simply says one row is affected. Now let's customize this message by adding in a trigger. I'm going to click here at the end of line number 13 and come down to line 15, and then scroll my window down just a little bit so I have more room to type. We start creating the trigger with the CREATE TRIGGER keywords. Then we'll name the trigger and put it inside of the same schema…
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
-
-
-
-
-
-
-
-
-
Automate SQL Server with triggers1m 48s
-
(Locked)
What are SQL Server triggers?3m 37s
-
(Locked)
Two triggers types: INSTEAD OF and AFTER2m 34s
-
(Locked)
Create a trigger to print a message6m 17s
-
Timestamp a table modification5m 31s
-
(Locked)
Firing INSTEAD OF triggers3m 23s
-
(Locked)
Challenge: Create a trigger58s
-
(Locked)
Solution: Create a trigger7m 10s
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-