I need to update the DateModified Column without knowing the name of the Primary Key Column.
Basically, I’ve got a plain-jane UPDATE trigger like this:
CREATE TRIGGER updated_SCHEMA_TABLE
ON [SCHEMA].[TABLE]
AFTER UPDATE AS
BEGIN
SET NOCOUNT ON;
UPDATE [SCHEMA].[TABLE]
SET DateModified = getdate()
WHERE [PRIMARYKEY]
IN (SELECT [PRIMARYKEY]
FROM Inserted)
END
but won’t know the primary key’s column name because the trigger will be generated programmatically (see this question as to why).
Is this possible?
OK, perhaps I was a bit unfair leaving this part as an “exercise” in the previous question.
This would work for tables with a single column PK. It might be easiest to start with these and then go back and manually adjust those with a composite PK.