Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
deleting huge records From Table
20 posts, Page 1 of 2
1
2
»»
deleting huge records From Table
Rate Topic
Display Mode
Topic Options
Author
Message
sharath.chalamgari
sharath.chalamgari
Posted Sunday, November 21, 2010 11:22 PM
Ten Centuries
Group: General Forum Members
Last Login: Monday, September 17, 2012 7:30 AM
Points: 1,038,
Visits: 679
i have a table with more than a 30 million Records in it.
because of soem performance related issues we need to delete some unwanted records (around 15 millon)from it and we have identified the filter conditions to remove the same. regarding this i need help on the following.
1) What are all the stpes that i need to take care when we are deleting such huge records from the database
2) How to estimate the time that is going to take when deleting such a huge records.
thanks in advance.
Post #1024149
Eralper
Eralper
Posted Sunday, November 21, 2010 11:32 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
If you have foreign keys, constraints etc it will take a longer time to delete records from sql table.
Also it will be better I guess to disable indexes (delete indexes) and then after deletion of unwanted rows recreate the indexes again. This will save server to update the indexes after every DML operation on the table.
Eralper
SQL Server and T-SQL Tutorials and Articles
Microsoft Certification and Certification Exams
Post #1024151
sharath.chalamgari
sharath.chalamgari
Posted Sunday, November 21, 2010 11:58 PM
Ten Centuries
Group: General Forum Members
Last Login: Monday, September 17, 2012 7:30 AM
Points: 1,038,
Visits: 679
Eralper (11/21/2010)
If you have foreign keys, constraints etc it will take a longer time to delete records from sql table.
Also it will be better I guess to disable indexes (delete indexes) and then after deletion of unwanted rows recreate the indexes again. This will save server to update the indexes after every DML operation on the table.
Thanks for ur Quick Reply, The table does not have any relationship with other tables.
as u said there is an index on the table, so i need to delete the index and recreate it back once the delete operation is done.
what about log file? will it becomes huge in deleting these records?
Post #1024154
Eralper
Eralper
Posted Monday, November 22, 2010 12:06 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
Yes, that is an important topic.
If you could truncate than there will be no problem. But since you want to keep some of the records in the table, then DELETE operation will be done. So log file will have entries for each delete command.
You can also alter the recovery model of your database to keep the log file size smaller.
You can change it to simple recovery model if it is set to full recovery model now.
Eralper
SQL Server and T-SQL Tutorials and Articles
Microsoft Certification and Certification Exams
Post #1024156
balaji.ganga
balaji.ganga
Posted Monday, November 22, 2010 12:12 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Thursday, February 03, 2011 3:00 AM
Points: 164,
Visits: 656
Hi,
Once you delete the 15 million records from that table. then you cannot reuse the unused space and also the db size will not be decrease.If you want to decrease the db size. then you have to shrink the data file. So that only it will recover the unused space.
Thanks
Balaji.G
Post #1024157
Eralper
Eralper
Posted Monday, November 22, 2010 12:13 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
You can also backup transaction log and reduce the size by deleting after 100000 rows for example, then continue with an other 100000 delete, etc.
Eralper
SQL Server and T-SQL Tutorials and Articles
Microsoft Certification and Certification Exams
Post #1024159
Jeff Moden
Jeff Moden
Posted Monday, November 22, 2010 12:49 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 7:51 PM
Points: 32,910,
Visits: 26,800
You can get around some of the logging issues by using a SELECT/INTO to copy only the rows you want to keep and then renaming the table(s). Read up in Books Online on how to make SELECT/INTO minimally log.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1024170
Eralper
Eralper
Posted Monday, November 22, 2010 12:56 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 6:49 AM
Points: 178,
Visits: 463
Thanks Jeff,
I checked the BOL and I found :
The amount of logging for SELECT...INTO depends on the recovery model in effect for the database. Under the simple recovery model or bulk-logged recovery model, bulk operations are minimally logged. With minimal logging, using the SELECT… INTO statement can be more efficient than creating a table and then populating the table with an INSERT statement.
So I think populating a new table and then truncating the other might be more efficient when log size is considered.
Eralper
SQL Server and T-SQL Tutorials and Articles
Microsoft Certification and Certification Exams
Post #1024171
sharath.chalamgari
sharath.chalamgari
Posted Monday, November 22, 2010 1:26 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, September 17, 2012 7:30 AM
Points: 1,038,
Visits: 679
Thanks to Jeff and eralper on your valuable Inputs.
Post #1024183
Jeff Moden
Jeff Moden
Posted Monday, November 22, 2010 6:10 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 7:51 PM
Points: 32,910,
Visits: 26,800
Eralper (11/22/2010)
Thanks Jeff,
I checked the BOL and I found :
The amount of logging for SELECT...INTO depends on the recovery model in effect for the database. Under the simple recovery model or bulk-logged recovery model, bulk operations are minimally logged. With minimal logging, using the SELECT… INTO statement can be more efficient than creating a table and then populating the table with an INSERT statement.
So I think populating a new table and then truncating the other might be more efficient when log size is considered.
I agree. Just to be clear for folks that may think of doing it, don't ever shift from FULL recovery to SIMPLE recovery for the sake of archiving data because it will break the log chain for backups. It's ok to shift from FULL recovery to the BULK-LOGGED recovery, though.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1024269
« Prev Topic
|
Next Topic »
20 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.