473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Massive delete in DB

Hello,
I have a huge database (2 GB / month) and after a while it is becoming
non-operational (time-outs, etc.) So I have written an SQL sentence
(delete) that can reduce around 60% of the db size without compromising
the application data needs. The problem is that when I execute it, the
db does reduce its size 60%, but the transaction log increases at the
same rate. Can I execute the sentence in a "commit" or
"transaction" mode so to impede the SQL Server write in the log?

Thanks for the help!

Antonio

Sep 6 '05 #1
6 4961
You can't stop MSSQL using the log, but you can break a single DELETE
into multiple batches (see example below). If you back up the
transaction log from time to time during the batch delete (or put the
database in single user mode first), this should keep the log size
under control. It would probably be a good idea to try it out on a test
system first, and also make a full backup before starting, just in case
something goes wrong.

Simon

set rowcount 50000 -- or whatever

delete from dbo.MyTable
where ...

while @@rowcount > 0
delete from dbo.MyTable
where ...

set rowcount 0

Sep 6 '05 #2
Sorry - a mistake in the comments above. "single user" should be
"simple recovery".

Simon

Sep 6 '05 #3
Hi Simon

If possible it may be advisable to do both!

John
"Simon Hayes" <sq*@hayes.ch> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Sorry - a mistake in the comments above. "single user" should be
"simple recovery".

Simon

Sep 6 '05 #4
John,

Yes, absolutely right. Personally I would aim to do it in an overnight
job, with the users locked out of the database as you suggest.

Simon

Sep 6 '05 #5
AK
instead of deleting tons of rows, you could SELECT INTO <new table> the
rows you intend to keep, drop the old table, and rename the new one.
Could be much faster

Sep 6 '05 #6
DH
"AK" <AK************@hotmail.COM> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
instead of deleting tons of rows, you could SELECT INTO <new table> the
rows you intend to keep, drop the old table, and rename the new one.
Could be much faster


Or BCP the WANTED data out (you can create a view of the wanted records and
bcp from the view), drop indexes, truncate, load it back in and reindex.
BCP can be done as a mostly unlogged operation.

One way or another, you probably want to reindex to reorganize the table.

I recommend:
1. Testing with a small quantity of data in test tables and view with same
structure as real tables.
2. Good backups.
- or -
A strong, good-looking resume all printed and ready to roll.
Sep 8 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: nasht | last post by:
Hi, I'm trying to make a newsletter application in php (using mail() ). This application is supposed to look in a MySQL database and generate a list of emails and first names. Then it should...
12
by: MikeT | last post by:
I have a page that produces little thumbnails of the 3D models it finds in a specified directory (and iterates down through any sub directories). It basically scans each directory for 3D Studio...
11
by: suma | last post by:
Hello, I want to delete duplicate rows in a table when no primary key is defined. For eg: If we have table1 with data as below, Suma 23 100 Suma 23 100 I want to delete a row from this...
15
by: rlayberry | last post by:
Hi I have found what looks like a huge bug in MSAccess. When I have the following in a table in Access 1996 0.08715292
1
by: | last post by:
Hi- I was curious if anyone has had good luck using one of the commercial .NET FTP client libraries to perform massive LIST commands. I have tried various free libraries with no/little success,...
4
by: Will Lastname | last post by:
I'm creating an application that allows a user to enter multiple items that correspond to a single collection. The idea is that they enter the product in the textbox, hit submit, repeat.... ...
2
by: rich | last post by:
I am building a database and I am using a list where I can make multiple choices. The data is like this Master table item1id item2 index(item1id) detail table item1id
0
by: axas | last post by:
How can I delete multiple records from a DataGrid? Thanks a lot.
15
by: jools | last post by:
I'm having trouble modifying some code written by someone else. The code is very dense and obscure but does work fine. However I need to insert a block of my own and I've hit what I assume is a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.