Agree, this should be the default for unique indexes. Why would you ever want multiple NULLs in an unique index?
Agree, this should be the default for unique indexes. Why would you ever want multiple NULLs in an unique index?
This also fits perfectly well with the normal interpretation / treatment of sql null as “not a value”.
That's what this change prohibits.
What.
> That's what this change prohibits.
This change prohibits nothing, it allows specifying something (which was a bit complicated to enforce before).
It allows specifying a constraint - that you can't have two rows with the same values even if one of the values is a NULL. That's prohibiting duplicate NULLs. The change allows you to prohibit duplicate NULLs.
Say you have a table (EmployeeName, CarID). You could do a UNIQUE constraint on those two attributes, but that would still allow:
EmployeeName | CarID
Jeff | 2
Kim | NULL
Kim | NULL
Here, "Kim" is car-less (NULL in the CarID field) twice, which makes no sense.
Hence the new constraint.
Sure.
> Here, "Kim" is car-less (NULL in the CarID field) twice, which makes no sense.
The relation makes no sense to start with, it didn’t need duplicate nulls for that.
unique (EmployeeName), unique (EmployeeName, CarID)
And if this is your employee table, you’d have UNIQUE (EmployeeData) and UNIQUE (CarID), and it would do what you want.
Since employees can only have one car and since a car can only be used by one employee, an unique index is fine, but there may be 20 people that don't have a car so you don't want NULL values to be unique.
Of course there are always ways to work around this, but this is the general idea.
I am not sure if this really is a great modelling. If a user happens to have two logins in your table (maybe they signed up with two different emails), and then connects one of his accounts with his FB identity, what does it mean that the other entry cannot be connected to the FB identity?
It would be weird to expect that only one person does not have SSN.
Of course, the workaround for such cases is simple: have a sentinel value for unassisted sales and make the column not nullable.
But yes, even if no nulls are present in any table, outer join could (or maybe even should) introduce them.
You would maybe want some value to be unique if it exists.
In some cases the above is actually important, whereas in others you may want to treat NULL as a "value" instead.
Or "payment vendor processing ID". You may have multiple entries not yet sent to the vendor, so they're NULL.
This shows up literally all the time in SQL schemas.