sql - In an UPDATE trigger - get the Primary Key without the column's name -


I need to update date formatted columns without knowing the name of the primary key column.

Actually, I got a simple -jen update trigger in this way:

  Update Trigger has been updated to [SCHEMA]. [Table] After updating after updating; Update [SCHEMA] [Table] SET DateModified = getdate () WHERE [PRIMARYKEY] IN (SELECT [PRIMARYKEY] inserted) END  

But the column name of the primary key does not know because the trigger is programmatically () Will arise.

Is this possible?

Okay, maybe I was slightly inappropriate except in this article as an "exercise" in the previous paragraph

This will work for tables with a single column PK. It can be easiest to start with them and then go back and adjust them manually with the overall PK.

  Update trigger trigger _ '+ s.name +' _ '+ t.name +' on '+ (name SN) +'. ' + Cotename (TNN) + 'After update' + 'Start' + 'Set knockout on; '+' Update T '+' Set [DateModified] = getdate () Include '+' I '+' Inner Join '+ Cotename (SN) +' '+ Kotamam (T. Names) +' T '+' On I '.' + Kota Name (c2.name) + '= T.' + Quota name (c2.name) + 'end' from sys.column to join c inrol, sys.tables tc .object_id = t.object_id Internal joining sys.schemas s on t.schema_id = s.schema_id Internal Join sys.indexes i I.object_id at i.object_id = i.object_id on IC.object_id ICIIDIBIDIIDIIIDICIDIID and i.index_id = ic.index_id IOCObject_ID and ic.index_id = Internal linking on sys.columns c2. .column_id where c.name = 'DateModified' and t.type = 'U' and i.is_primary_key = 1  

Comments