title: t-sql get the primary key's column name when using Change Tracking - Changetable
body: <p>I am trying to get the changes from Change tracking dynamically.</p>
  <pre><code>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 &lt;= CHANGE_TRACKING_CURRENT_VERSION()
  </code></pre>
  <p>Is there a way to get the primary key's column name from the Change tracking / ChangeTable?</p>
  <p>In the documentation <a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-functions/changetable-transact-sql?view=sql-server-ver15" rel="nofollow noreferrer">on ChangeTable</a> there is reference to column_name for primary keys but I my guess is this is input and not output...</p>
  <p>The column name is in there, if you execute:</p>
  <pre><code>select CT.* 
  from CHANGETABLE(CHANGES [Table Name], [start version]) as CT 
  where CT.SYS_CHANGE_VERSION &lt;= CHANGE_TRACKING_CURRENT_VERSION()
  </code></pre>
  <p>Your thoughts would be much appreciated.</p>