NOTE. This answer relates to enterprise-class development.
This is an RDBMS problem, not just SQL Server, and the behavior can be very interesting. For one, although it is usually indexed automatically (unambiguously) for primary keys, it is NOT absolute. There are times when it is important that the primary key is NOT uniquely indexed.
In most RDBMSs, a unique index will be automatically created on the primary key, if it does not already exist. So you can create your own index in the primary key column before declaring it as a primary key, then this index will be used (if acceptable) by the database engine when applying the primary key declaration. Often you can create a primary key and allow its unique index by default, then create your own alternate index in that column and then drop the default index.
Now for the fun part - when do you NOT want a unique primary key index? You do not want this and cannot endure one when your table receives enough data (rows) to maintain the index index too expensive. It depends on the hardware, the RDBMS mechanism, the characteristics of the table and database, and the system load. However, it usually begins to appear as soon as the table reaches several million rows.
A significant problem is that each row insertion or update of a primary key column scans the index for uniqueness. This unique index scan (or its equivalent in any of the DBMSs) becomes much more expensive as the table grows until it becomes dominant in the performance of the table.
I have repeatedly dealt with this problem with tables up to two billion rows long, 8 TB of storage and forty million row inserts per day. I was instructed to redesign the system involved, which included abandoning the unique primary key index practically as a first step. Indeed, the abandonment of this index was necessary in production simply to recover from a failure before we even approached the redesign. This redesign included finding other ways to ensure the uniqueness of the primary key and provide quick access to data.
Rob Williams Jan 20 '09 at 20:07 2009-01-20 20:07
source share