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

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.

Contents