FIX: Job Step Fails if First INSERT of Batch Job Encounters a Msg 3604 Error

Article translations Article translations
Article ID: 295032 - View products that this article applies to.
This article was previously published under Q295032
BUG #: 351328 (SHILOH_BUGS)
BUG #: 100729 (SQLBUG_70)
Expand all | Collapse all

On This Page

SYMPTOMS

If a job contains a single INSERT statement on a table that has a unique index with the IGNORE_DUP_KEY clause, and the INSERT violates the uniqueness property of the index, the corresponding row is not inserted in the table. The job step fails, and you see the following message in the job step history:
Duplicate key was ignored. [SQLSTATE 23000] (Message 3604). The step failed.
Because the table has an UNIQUE INDEX with IGNORE_DUP_KEY, the INSERT statement should be ignored and the step should succeed.

RESOLUTION

To resolve this problem, obtain the latest service pack for 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

If you place a "dummy" SELECT statement that always executes successfully (such as SELECT 1) just before the INSERT statement that fails with the 3604 error, the step succeeds. This is demonstrated in the "More Information" section.

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 SQL Server 2000 Service Pack 1.

MORE INFORMATION

Steps To Reproduce Behavior

  1. Create a table test in the pubs database and execute the following script to insert a row:
    USE pubs
    CREATE TABLE test(i int)
    CREATE UNIQUE INDEX uniq_t1_i on test(i) with IGNORE_DUP_KEY
    INSERT INTO test VALUES(1)
    					
  2. Create a T-SQL job in the pubs database to insert a row in table test:
    INSERT INTO pubs..test values(1)
    					
  3. Run the job. The job fails, and the job step history shows the error listed in the "Symptoms" section.
  4. Note that if we add a successful statement after the INSERT that encounters a 3604 error:
    INSERT INTO pubs..test values(1)
    INSERT INTO pubs..test values(2)
    					
    the step fails again with the following error:
    Duplicate key was ignored. [SQLSTATE 23000] (Message 3604) Associated statement is not prepared [SQLSTATE HY007] (Error 0). The step failed.
  5. However, if we add a successful statement that has results before the INSERT that fails with the 3604 error:
    insert pubs..t1 values(3)
    insert pubs..t1 values(1)
    					
    the step succeeds, and we see the following message:
    Duplicate key was ignored. [SQLSTATE 23000] (Message 3604). The step succeeded.

Properties

Article ID: 295032 - Last Review: October 28, 2003 - Revision: 3.2
APPLIES TO
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
Keywords: 
kbbug kbfix kbsqlserv2000sp1fix KB295032

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com