Microsoft KB Archive/308811

= FIX: SELECT DISTINCT Operation Generates 1505 Error Message =

Article ID: 308811

Article Last Modified on 10/16/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q308811



BUG #:354864 (SHILOH_BUGS)

BUG #:355027 (SHILOH_BUGS)



SYMPTOMS
When you use a SELECT DISTINCT operation from another table to insert data into an empty table, you expect for a unique index to be built on the table. However, the attempt to create a unique index may fail with the following 1505 error message for data that was implicitly converted during the insert:

Server: Msg 1505, Level 16, State 1, Line 1

CREATE UNIQUE INDEX terminated because a duplicate key was found for index ID %d. Most significant primary key is '%S_KEY'.



CAUSE
This behavior can occur if, for certain implicit data type conversions, the DISTINCT operation is performed at the wrong time and fails to remove all of the duplicate rows.



RESOLUTION
To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack



WORKAROUND
To work around this issue, create the unique index with the IGNORE_DUP_KEY clause before you insert the data.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was first corrected in Microsoft SQL Server 2000 Service Pack 2.



MORE INFORMATION
Some examples of implicit conversions include the following:
 * char to nchar (Unicode)
 * smalldatetime to datetime

For more information about implicit conversions, see the following topics in Books Online:
 * Data Type Conversion
 * CAST and CONVERT
 * Conversion Functions

Additional query words: datatype data type wrong incorrect collate unicode

Keywords: kberrmsg kbbug kbfix KB308811

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.