I have two tables. One table is restaurant, and the other is restaurant_changes. Restaurant contains attributes, id, name, address, city, state, zip. While restaurant_changes contains all of those but also a timestamp.
Whenever a change is made to restaurant I want it to be noted in the restaurant_changes table. It does it by storing a timestamp and the rest of the row before changes. So if restaurant name changes from A to B in restaurant_changes, the name A will be stored.
Here is what I'm trying to do and I'm hoping I can get steered in the correct direction.
create trigger change_restaurant after update on restaurant
referencing old table as otab
referencing new table as tab
Declare @today DATETIME = SYSDATETIME()
for each row
insert into restaurant_changes
select(@today, otab.id, otab.name, otab.address, otab.city, otab.state, otab.zip
from otab
inner join ntab
on otab.id = ntab.id)