SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Delete from very large multiple tables


Delete from very large multiple tables

Author
Message
EasyBoy
EasyBoy
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4216 Visits: 939
We have a situation where we would like to delete from multiple tables (60-70 tables) and keep data from only 2 years and current financial year . They all are very large (millions of rows).
Based on date from one table we need to find appropriate ID value from all 60-70 tables.
ID is the PK in all tables. In additional, data are replicated through replication.
What would be the best way to delete the records from all tables without affecting replication?
Thanks in advance.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (390K reputation)SSC Guru (390K reputation)SSC Guru (390K reputation)SSC Guru (390K reputation)SSC Guru (390K reputation)SSC Guru (390K reputation)SSC Guru (390K reputation)SSC Guru (390K reputation)

Group: General Forum Members
Points: 390395 Visits: 42807
EasyBoy - Monday, February 5, 2018 11:38 AM
We have a situation where we would like to delete from multiple tables (60-70 tables) and keep data from only 2 years and current financial year . They all are very large (millions of rows).
Based on date from one table we need to find appropriate ID value from all 60-70 tables.
ID is the PK in all tables. In additional, data are replicated through replication.
What would be the best way to delete the records from all tables without affecting replication?
Thanks in advance.


Well, replication throws a wrench in what I would consider unless it is something you could tear down and rebuild.

Regarding the deletion of data my first question is to ask what is the ration of data being kept to data being deleted. That alone will have an impact in how you approach the task.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Arsh
Arsh
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5061 Visits: 998
Lynn Pettis - Monday, February 5, 2018 12:37 PM


Well, replication throws a wrench in what I would consider unless it is something you could tear down and rebuild.

Regarding the deletion of data my first question is to ask what is the ration of data being kept to data being deleted. That alone will have an impact in how you approach the task.

Agree with the question from Lynn. The ratio of data volume to remain TO the data volume to remove becomes crucial . It then helps to favour other options , like extracting the required data (if its significantly less than the data to remove) to a staging DB and then dropping this database altogether.

Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (869K reputation)SSC Guru (869K reputation)SSC Guru (869K reputation)SSC Guru (869K reputation)SSC Guru (869K reputation)SSC Guru (869K reputation)SSC Guru (869K reputation)SSC Guru (869K reputation)

Group: General Forum Members
Points: 869997 Visits: 47405
Arsh - Tuesday, February 6, 2018 1:21 PM
Lynn Pettis - Monday, February 5, 2018 12:37 PM


Well, replication throws a wrench in what I would consider unless it is something you could tear down and rebuild.

Regarding the deletion of data my first question is to ask what is the ration of data being kept to data being deleted. That alone will have an impact in how you approach the task.

Agree with the question from Lynn. The ratio of data volume to remain TO the data volume to remove becomes crucial . It then helps to favour other options , like extracting the required data (if its significantly less than the data to remove) to a staging DB and then dropping this database altogether.


I've found that, especially for large tables, even if only 30-50% of the table is going to be deleted, it's usually much more effective to use the copy-swap-and-drop method because, done correctly, it can still be twice (or more) as fast and a whole lot easier on the transaction log if you make an excursion to the BULK LOGGED Recovery Model and take advantage of "Minimal Logging" with the Clustered Index already in place.

IMHO, the jury is still out on the use of TF 610 for other indexes. It's usually faster just to rebuild the NCIs while in the BULK LOGGED Recovery Model.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search