title: SQL Server select primary key from table where the key contains multiple columns
body: <p>I am working on a legacy database. I am not able to change the schema :( in a couple of tables the primary key uses multiple columns.</p>
  
  <p>In the app I read the data in each row into a table the user then updates the data and I write the data back into the table.</p>
  
  <p>Currently I concatenate the various PK columns and store them as a unique id for when I put the data back into the table.</p>
  
  <p>Now I was wondering if there is a more efficient way to do that. Coming from a mySQL background I am not aware of any but thought SQL Server 2005 may have a function</p>
  
  <pre><code>SELECT PRIMARYKEY() as pk, ...  FROM table WHERE ... 
  </code></pre>
  
  <p>the above would select the key that the database engine uses as the primary key for the given record</p>
  
  <p>I searched and couldn't find anything. Its probably just me being fussy but I don't like the concatenation trick.</p>
  
  <p>DC</p>