I'd just like to clarify something pretty simple regarding single and composite UNIQUE
constraints that I can't find a clear answer to.
Assume I have the following table:
CREATE TABLE person (
id INT PRIMARY KEY,
customer_id INT NOT NULL UNIQUE,
name VARCHAR(20) NOT NULL
...
)
Would it be safe to say that adding the following constraint:
UNIQUE(customer_id, name)
would be redundant and offer no benefit under any circumstance? In other words, is it useless to create a composite UNIQUE
constraint that includes a column which is already UNIQUE
?
This appears to make logical sense, but as I stated, I couldn't find an answer confirming it.
INCLUDE
on indexes. Out of curiosity, why is there bothid
andcustomer_id
if they are both unique? Shouldn't they be the same column?UNIQUE(name)
should do it -id
is just a surrogate!