't-sql get the primary key's column name when using Change Tracking - Changetable
I am trying to get the changes from Change tracking dynamically.
select [tableName].*, CT.SYS_CHANGE_VERSION, SYS_CHANGE_OPERATION
from [tableName]
right outer join
CHANGETABLE(CHANGES [tableName], [start version]) as CT on [tableName].[Table's Primary Key] = CT.[Table's Primary Key]
where CT.SYS_CHANGE_VERSION <= CHANGE_TRACKING_CURRENT_VERSION()
Is there a way to get the primary key's column name from the Change tracking / ChangeTable?
In the documentation on ChangeTable there is reference to column_name for primary keys but I my guess is this is input and not output...
The column name is in there, if you execute:
select CT.*
from CHANGETABLE(CHANGES [Table Name], [start version]) as CT
where CT.SYS_CHANGE_VERSION <= CHANGE_TRACKING_CURRENT_VERSION()
Your thoughts would be much appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
