title: SQL Server unique GUID
body: <p>I understand in SQL Server GUIDs are MOSTLY unique, and also that the likelihood of a collision is remote, yet at the same time someone must win the lottery so I feel like it makes some sense to prepare for the possibility.</p>
  
  <p>Which is faster/better practice</p>
  
  <p>Using a technique where I assign a new GUID directly by just inserting a row and checking for an error (@@ERROR &lt;> 0) and repeating until I don't get an error [which I suppose in theory would only at worst be once...]</p>
  
  <p>or using an approach like this</p>
  
  <pre><code>DECLARE @MyGUID uniqueidentifier
  SELECT @MyGUID = NewID()
  if exists(select * from tablename where UserID=@MyGUID)
  </code></pre>
  
  <p>and looping over that till I find one not in use.</p>
  
  <p>I like the 2nd approach because I can then have the GUID for use later on in the Stored Procedure so I'm currently leaning towards that one.</p>