BUG: Command Aborted When Inserting into a IGNORE_DUP_KEY Table

Last reviewed: July 30, 1997
Article ID: Q171886
The information in this article applies to:
  • Microsoft SQL Server, version 6.5
BUG #: 17094

SYMPTOMS

An attempt to insert duplicates into a table with the IGNORE_DUP_KEY option set ON may cause an INSERT INTO command to be aborted. The following scripts demonstrate this problem:

   SET NOCOUNT ON
   DROP TABLE t1
   GO
   DROP TABLE t2
   GO

   CREATE TABLE t1 (c INT)
   CREATE UNIQUE INDEX ind ON t1(c) WITH IGNORE_DUP_KEY

   SELECT c = 1
   INTO t2
   UNION ALL
   SELECT 1

   INSERT INTO t1(c)
      SELECT c
         FROM t2 WHERE NOT EXISTS (SELECT * FROM t1 WHERE t1.c = t2.c)

WORKAROUND

To work around this problem, do either of the following:

  • INSERT with "DISTINCT" and "NOT EXISTS" clauses, as in the following example:

          INSERT INTO t1 (c)
    
             SELECT DISTINCT c
                FROM t2 WHERE NOT EXISTS (SELECT * FROM t1 WHERE t1.c = t2.c)
    
       -or-
    
    
  • INSERT without using a "NOT EXISTS" clause, as in the following example:

          INSERT INTO t1 (c)
    
             SELECT c
                FROM t2
    
    

STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional query words: tsql transql transact-sql
Keywords : kbbug6.50 SSrvTran_SQL kbusage
Version : 6.5
Platform : WINDOWS
Issue type : kbbug
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.