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.
Challenge: Create a trigger - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Challenge: Create a trigger
We've seen a couple of triggers that you can apply to data manipulation commands sent to SQL Server tables. Now, it's a good time to take a moment to try out what you've learned. In the Chapter 1 folder of the exercise files, I've created a small script called ChallengeOne-Start.sql. It'll build a table structure to store product categories in the KinetEcoTRG database. I'd like you to add three different triggers to the table. One will fill in the CreationDate whenever a new row is inserted into the table. The second trigger will update the LastModifiedDate column whenever a row is updated, and finally, create a trigger that will prevent any delete operations from removing rows from the table. When you're done creating your triggers, execute the lines in the script to test your solution and see if you get the expected results. This challenge should take you about 10 minutes to complete. Good luck.
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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-