Dit komt neer op een veelgemaakt misverstand. De UNIQUE-constraint doet al precies wat je wilt — een kolom die UNIQUE is, kan rustig meerdere NULL-waarden bevatten.
De handleiding zegt het duidelijk:
In general, a unique constraint is violated when there is more than one row in the table where the values of all of the columns included in the constraint are equal. However, two null values are not considered equal in this comparison. That means even in the presence of a unique constraint it is possible to store duplicate rows that contain a null value in at least one of the constrained columns. This behavior conforms to the SQL standard, but we have heard that other SQL databases might not follow this rule. So be careful when developing applications that are intended to be portable.
(De vette nadruk is van mij.)
Eén ding om te onthouden: tekentypes accepteren ook een lege string (''), wat niet hetzelfde is als NULL. Een lege string veroorzaakt net als elke andere niet-NULL-waarde een unique-overtreding zodra die in meer dan één rij voorkomt.