this is your main difference:
UNIQUE constraints can be defined on columns that allow null values, whereas PRIMARY KEY constraints can be defined only on columns that do not allow null values
When to use one over the other?
Although both a UNIQUE constraint and a PRIMARY KEY constraint enforce uniqueness, use a UNIQUE constraint instead of a PRIMARY KEY constraint when you want to enforce the uniqueness of:
A column, or combination of columns, that is not the primary key.
Multiple UNIQUE constraints can be defined on a table, whereas only one PRIMARY KEY constraint can be defined on a table.
For SQL Server both do the same. Create unique constraint, and unique index will be created. Create unique index, no dupes will be allowed on indexed column(s). The only difference is semantical - "constraint" is more logical term, while "index" is it's physical implementation.
For some relational databases (early Watcom/Sybase comes to mind) that distinction made sense. There you could create unique constraint without index.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.