Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Delete/insert transaction fails on copy of database

$
0
0

Hello, we have a transaction that runs to completion on one database but errors out on a copy of the database (recovered from a backup). Here is the transaction:

use RAD;

BEGIN

TRANT;

delete

fromrops.SchedulewherePeriodID= 5andSuccessorAgencyID= 388;

insert

intoRAD.rops.Schedule

FinalBoolean,LastUpdDate,LastUpdUser,SANote,OBApprovedDate,OBLetter,PeriodID,SuccessorAgencyID,SASchedule)values('N','2013-08-12','west0388',null,null,null, 5, 388,null);

COMMIT TRAN T;

On the first database, results are:

(1 row(s) affected)

(1 row(s) affected)

On the copied database, results are:

(0 row(s) affected)

Msg 2601, Level 14, State 1, Line 4

Cannot insert duplicate key row in object 'rops.Schedule' with unique index 'uk_ScheduleSuccessorAgencyPeriod'. The duplicate key value is (5, 388).

The statement has been terminated.

Yes, there is a difference, the row exists in the first database but not the second. But when we try the same query with different values in the first database on a non-existent row, it still succeeds.

This is a SQL Server 2008 Standard version 10.0.5500 database running on Windows 2008 64-bit. Schedule is a 10-column table with an integer identity key, one varchar(8000), one varbinary(max), remainder of columns "normal", there are less than 800 rows. There are a number of cascade delete foreign keys with "Schedule" as the parent table. Also there is a unique index on Schedule on columns (PeriodID, SuccessorAgencyID) with includes column (FinalBoolean). However the includes column has no effect, I removed it from the unique index but that made no difference.


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>