Unique constraint vs unique index
From: Tom Edelbrok (anonymous_at_anonymous.com)
Date: 06/10/04
- Previous message: PGA: "Re: very simple query but wrong. WHY ?"
- Next in thread: WangKhar: "Re: Unique constraint vs unique index"
- Reply: WangKhar: "Re: Unique constraint vs unique index"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Jun 2004 17:48:45 GMT
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
- Previous message: PGA: "Re: very simple query but wrong. WHY ?"
- Next in thread: WangKhar: "Re: Unique constraint vs unique index"
- Reply: WangKhar: "Re: Unique constraint vs unique index"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|