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


Deleting Large Volumes of records


Deleting Large Volumes of records

Author
Message
alan_b
alan_b
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 55
I have a logging table that has 130+million rows in it and it is taking up over 11gb in disk space between the data and indexes.

Ideally I want to reduce the database size and improve my index performance by deleting obsolete data over a year old, which would leave me with about 20m records.

If I delete the redundant data, my understanding is that my overall database size won't reduce unless I shrink the database, which I want to avoid. Is that correct?

What happens to the re-allocated space then? Is it made available across the database for re-use or is it only used for growth on my original table?
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15978 Visits: 19524
Today's ssc headlines include an article by Hugo Cornelis on partitioning logging tables to enable fast deletes. It's a step by step how-to guide and covers partitioning an existing table. Right up your street.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Eric M Russell
Eric M Russell
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11964 Visits: 10622
If this is something like an audit log that's accumulates GB of data and is only occasionally queried, then you want to consider inserting these records into an external file, rather than containing them in a database table. Database storage is a lot more expensive and problematic to manage than the file system, and this would keep your backups a lot smaller.
Below is a T-SQL solution that uses openrowset and the OLEDB provider for text files. In this example, the file sysobjects.csv should pre-exist in a folder on the database server or a network folder that is accessible by the SQL service account. The first row should contain the header, in this case "A,B". Also, to use openrowset, you need to have the server option 'Ad Hoc Distributed Queries' enabled.
insert into openrowset
(
'Microsoft.Jet.OLEDB.4.0',
'Text;Database=C:\TEMP\;HDR=Yes;',
'select A, B from sysobjects.csv'
)
select object_id, schema_id
from sys.objects




"The universe is complicated and for the most part beyond your control, but your life is only as complicated as you choose it to be."
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