Link to home
Start Free TrialLog in
Avatar of William White
William WhiteFlag for United States of America

asked on

Batch Delete Script

I am trying to build a script that will delete a fixed number of records at a time, such as 10,000, from a table based on the primary key.   The table name is Trans and the primary key column name is ID.  In a separate table named TransIDsToDelete, I have one column named TransID which contains the IDs of the records I would like to delete from the Trans table.  The TransIDs are listed from lowest to highest.  Most of the TransIDs in the TransIDsToDelete table increment by 1, but occasionally there may be a very sudden increase in the value for the TransID.  For example the value for TransID may be 1500 for the 100th row, but the value for row 101 is 23989.  I would also like to specify the total number of records I'd like to delete, and have the script iterate through until that number is reached, and then terminate.  Can someone provide me with an example that deletes the records from the Trans table in batches of say 10000?
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The last example is too much. Either use SET ROWCOUNT or TOP, but in combination don't make sense.