title: How can I create a unique index in Oracle but ignore nulls?
body: <p>I am trying to create a unique constraint on two fields in a table.  However, there is a high likelihood that one will be null.  I only require that they be unique if both are not null (<code>name</code> will never be null).</p>
  
  <pre><code>create unique index "name_and_email" on user(name, email);
  </code></pre>
  
  <p>Ignore the semantics of the table and field names and whether that makes sense - I just made some up.</p>
  
  <p>Is there a way to create a unique constraint on these fields that will enforce uniqueness for two not null values, but ignore if there are multiple entries where <code>name</code> is not null and <code>email</code> is null?</p>
  
  <p>This question is for SQL Server, and I'm hoping that the answer is not the same:
  <a href="https://stackoverflow.com/questions/767657/how-do-i-create-unique-constraint-that-also-allows-nulls-in-sql-server">How do I create a unique constraint that also allows nulls?</a></p>