Trigger for denormalizing data
Posted on 2011-02-28
I am not totally new to SQL, but I am new to triggers and I know nothing about stored procedures. Let's assume I have a customer database with simple things like customer name, address, city, state and zip. I also have a foreign key to a table about how they heard about us. That table has a primary key and name (let's call it how_heard_key and how_heard_name).
so I have the how_heard_key in my customer database and I want to denormalize the how_heard_name in there as well.
Let's just assume that my front end for capturing data will only have the how_heard_key as part of the insert or update. How do I make a trigger so that anytime a user does any insert or update of the record that it denormalizes the how_heard_name into the customer table?
I think I want to do this behind the scenes with a trigger and not with any stored procedure, at least in this odd case.