I am having a very strange issue and looking for some ideas on next
troubleshooting steps.
Summary:
running a delete statement that matches multiple rows fails or
partially fails to delete those rows.
Description:
I am running Sybase ASE 15.0.0 and Solaris 10 with multiple zones. I
BCP 1.5 million rows of
data into a ProductStage table before running the following two
statements -
DELETE Product
FROM Product,
ProductStage (INDEX XPKProductStage)
WHERE Product.BatchNumber LIKE @[EMAIL PROTECTED]
AND Product.BatchNumber = ProductStage.BatchNumber
AND Product.Month = ProductStage.Month
AND Product.Agency = ProductStage.Agency
INSERT INTO Product(BatchNumber,Month,Agency,Address,CRP,CAM,WAL)
SELECT BatchNumber,Month,Agency,Address,CRP,CAM,WAL
FROM ProductStage (INDEX XPKProductStage)
WHERE BatchNumber LIKE @[EMAIL PROTECTED]
Note: batch numbers are three characters followed by three digits
like the following XFD001, XFD002, XFD003... so
a specific example of the run may look like this -
DELETE Product
FROM Product,
ProductStage (INDEX XPKProductStage)
WHERE Product.BatchNumber LIKE 'XFD%'
AND Product.BatchNumber = ProductStage.BatchNumber
AND Product.Month = ProductStage.Month
AND Product.Agency = ProductStage.Agency
INSERT INTO Product(BatchNumber,Month,Agency,Address,CRP,CAM,WAL)
SELECT ProductNumber,Month,Agency,Address,CRP,CAM,WAL
FROM ProductStage (INDEX XPKProductStage)
WHERE ProductNumber LIKE 'XFD%'
There are around 1500 different three character prefixes.
I can usually run this process about 10 times each time with similar
if not identical data without an issue. The process being
BCPing 1.5 million records into the ProductStage and then running
the delete and insert statements for each 'Batch'.
There are usually around 1500 batches with about 1000 rows each.
Eventually I will get the following error -
"Attempt to insert duplicate key row in object 'Product' with unique
index 'XPKProduct'". First how is that possible given
the previous delete and insert statements? The delete should make
sure that there are no duplicated records in the Cusomter table.
After getting this error once, the loads will always return the
duplicate index error for the same Batch. I can get it to work again
by BCPing out the data that is in Product and ProductStage, dropping
and recreating the tables, BCPing the data back into those tables
The next time I run the staging process it will run without issue
and work for around another 10 trys.
I did some more research and by running the delete and insert
manually for a given batch (LIKE 'XFD%') after getting the
"Attempt to insert duplicate key row in object 'Product' with unique
index 'XPKProduct'". error I found that sometimes it fails to
delete or sometime it will partially delete the rows in Product that
match the WHERE Product.BatchNumber LIKE 'XFD%'. In one particular
case there was 879 rows in bacth "LIKE 'XFD%'" running the delete
statement using isql would return (734 rows affected). I would then
run
the delete statement again and it would re****t (145 rows affected).
It would take two runs of the delete statement to delete the full
879 rows it should have!
I ran DBCC on the involved tables and they check out fine. I am at a
loss and not sure where to go from here. Any ideas?


|