Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Sybase > running a delet...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 2486 of 2544
Post > Topic >>

running a delete statement that matches multiple rows fails or

by alacrite@[EMAIL PROTECTED] Jun 3, 2008 at 07:19 PM

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?
 




 4 Posts in Topic:
running a delete statement that matches multiple rows fails or
alacrite@[EMAIL PROTECTED  2008-06-03 19:19:25 
Re: running a delete statement that matches multiple rows fails
Keith <keith.wingate@[  2008-06-04 05:11:59 
Re: running a delete statement that matches multiple rows fails
--CELKO-- <jcelko212@[  2008-06-04 07:23:32 
Re: running a delete statement that matches multiple rows fails
alacrite@[EMAIL PROTECTED  2008-06-04 08:36:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 21:37:21 CDT 2008.