How do I go about looping through all the tables that have the updated_at
column? I figured out how to find all the tables that have the column using information_schema.columns
like this:
SELECT TABLE_NAME FROM information_schema.columns WHERE COLUMN_NAME = 'updated_at'
But I have no idea how I would go about looping through all the tables to create the trigger to update the updated_at
column to the current time with SYSDATETIMEOFFSET()
when the row is updated?
EDIT: So I managed to figure out the iterating now using a cursor. but now im kind of confused about updating the date. So if I set an after update trigger to update the updated_at date, wouldn't that trigger an infinite loop?