title: SQL Server: selecting primary key number for a newly added row
body: <p>I'm currently using </p>
  
  <pre><code>SELECT MAX(CustomerID)...
  </code></pre>
  
  <p>to select the <code>CustomerID</code>, which is the primary key of the table, number of a newly added row because I need to use this number for another table that uses it as a foreign key. One row is added via <code>INSERT</code>, and one <code>SELECT</code> query is performed sequentially.</p>
  
  <p>Under column property in SQL Server Management Studio, I see the <code>Identity Increment</code> is set to <code>1</code>. Is there an unsafe reason to use <code>MAX(CustomerID)</code> to get what I need? The code will always be "one row INSERT and one SELECT queries" for this procedure. If there is a better way, what would that be? Perhaps, somewhere along the line, "get me the <code>CustomerID</code> of the newly added row"?</p>