I am using SQL Server 2008 R2.
I have two tables, ShoppingList and ShoppingListFood. ShoppingListFood is linked to ShoppingList via a foreign key on ShopListID. I wish to update the LastModifiedDate column in the ShoppingList table whenever there is any update / insert done at the ShoppingListFood table. Is it possible??
I googled and found that I need create trigger in stored procedure, but i know nothing about it, can anyone help??
Sure – no problem – try something like this:
Basically, this creates a trigger that will fire after INSERT and UPDATE on
ShoppingListFood– it will update theLastModifiedDateto “right now” for all rows that have been inserted and/or updated, based on the pseudo tableInsertedthat’s available inside a trigger.This pseudo table contains all rows that have been freshly inserted (with all their columns), as well as the new values for all rows that have been updated (again: all columns).