Re: Unique constraint vs unique index
From: WangKhar (Wangkhar_at_yahoo.com)
Date: 06/11/04
- Next message: Jason Mauss: "SQL Server History"
- Previous message: Tom Edelbrok: "Unique constraint vs unique index"
- In reply to: Tom Edelbrok: "Unique constraint vs unique index"
- Messages sorted by: [ date ] [ thread ]
Date: 11 Jun 2004 03:06:10 -0700
I think that at a simplified level if you just want the data to be
unique use a constraint. If you want it to be unique - and you want
to have an index too slap a unique index on. Of course the unique
index also has the ignore_duplicate_key option, which can be handy for
those who don't like verifying hteir data prior to insertion or
update.
"Tom Edelbrok" <anonymous@anonymous.com> wrote in message news:<1a1yc.30$%i1.24@edtnps89>...
> What is the difference between using a unique constraint and a unique index?
> The Microsoft SQL Books Online says:
>
> Specifying a unique index makes sense only when uniqueness is a
> characteristic of the data itself. If uniqueness must be enforced to ensure
> data integrity, create a UNIQUE or PRIMARY KEY constraint on the column
> rather than a unique index. For example, if you plan to query frequently on
> the Social Security number (ssn) column in the employee table (where the
> primary key is emp_id), and you want to ensure that Social Security numbers
> are unique, create a unique constraint on ssn. If the user enters the same
> Social Security number for more than one employee, an error is displayed.
>
>
>
> So what does it mean "a characteristic of the data itself"? What does SQL do
> differently when you choose one method over the other? In general, when I
> want a column in a table to be unique, how can I know whether to make a
> unique constraint or a unique index?
>
>
>
> Thanks in advance,
>
> Tom
- Next message: Jason Mauss: "SQL Server History"
- Previous message: Tom Edelbrok: "Unique constraint vs unique index"
- In reply to: Tom Edelbrok: "Unique constraint vs unique index"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|