RobertT687
Programmer
I have a MSSQL 6.5 database with several tables of over 1 million rows. I have a control table in another database on the same server with key fields to the rows I want to delete (approximately 800K rows in each of 4 tables). The control table called DBSdemo..pmt_rqst_purge_ctrl has the structure:
vendor_id char(10) NOT NULL,
vendor_loc_code char(3) NOT NULL,
pmt_rqst_nbr char(22) NOT NULL,
pmt_rqst_date datetime NOT NULL,
schld_pmt_nbr smallint NOT NULL
with a unique clustered index made up of all the columns in the order shown. The tables to be purged also have primary keys and/or unique clustered indexes containing all of the above columns plus one or two others.
I'm using code like the following to delete older data I no longer need, and it's taking FOREVER.
DECLARE @RowsDeleted int
SELECT @RowsDeleted = 0
SELECT "Starting purge of pmt_rqst_tax @" + convert(varchar(26),Getdate(),109)
pmt_rqst_tax_Loop:
SET ROWCOUNT 40000
DELETE FROM pmt_rqst_tax
FROM pmt_rqst_tax pr,
DBSdemo..pmt_rqst_purge_ctrl pc
WHERE pr.vendor_id = pc.vendor_id
AND pr.vendor_loc_code = pc.vendor_loc_code
AND pr.pmt_rqst_nbr = pc.pmt_rqst_nbr
AND pr.pmt_rqst_date = pc.pmt_rqst_date
AND pr.schld_pmt_nbr = pc.schld_pmt_nbr
SELECT @RowsDeleted = @@ROWCOUNT
IF @RowsDeleted > 0
Begin
DUMP Transaction DBSprqt WITH TRUNCATE_ONLY
SELECT @RowsDeleted = 0
GOTO pmt_rqst_tax_Loop
End
SELECT "Finished purge of pmt_rqst_tax @" + convert(varchar(26),Getdate(),109)
go
The ROWCOUNT limit is present only to keep the transaction log from filling up.
Can any one suggest an improved way to get the delete done quicker?
A test run on my backup server has been running for over ten hours. Its not in a loop, just VERY SLOW.
Thanks in advance!!
vendor_id char(10) NOT NULL,
vendor_loc_code char(3) NOT NULL,
pmt_rqst_nbr char(22) NOT NULL,
pmt_rqst_date datetime NOT NULL,
schld_pmt_nbr smallint NOT NULL
with a unique clustered index made up of all the columns in the order shown. The tables to be purged also have primary keys and/or unique clustered indexes containing all of the above columns plus one or two others.
I'm using code like the following to delete older data I no longer need, and it's taking FOREVER.
DECLARE @RowsDeleted int
SELECT @RowsDeleted = 0
SELECT "Starting purge of pmt_rqst_tax @" + convert(varchar(26),Getdate(),109)
pmt_rqst_tax_Loop:
SET ROWCOUNT 40000
DELETE FROM pmt_rqst_tax
FROM pmt_rqst_tax pr,
DBSdemo..pmt_rqst_purge_ctrl pc
WHERE pr.vendor_id = pc.vendor_id
AND pr.vendor_loc_code = pc.vendor_loc_code
AND pr.pmt_rqst_nbr = pc.pmt_rqst_nbr
AND pr.pmt_rqst_date = pc.pmt_rqst_date
AND pr.schld_pmt_nbr = pc.schld_pmt_nbr
SELECT @RowsDeleted = @@ROWCOUNT
IF @RowsDeleted > 0
Begin
DUMP Transaction DBSprqt WITH TRUNCATE_ONLY
SELECT @RowsDeleted = 0
GOTO pmt_rqst_tax_Loop
End
SELECT "Finished purge of pmt_rqst_tax @" + convert(varchar(26),Getdate(),109)
go
The ROWCOUNT limit is present only to keep the transaction log from filling up.
Can any one suggest an improved way to get the delete done quicker?
A test run on my backup server has been running for over ten hours. Its not in a loop, just VERY SLOW.
Thanks in advance!!