Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

delete query SQL 2008 in Virtual machine setup? Expand / Collapse
Author
Message
Posted Friday, March 15, 2013 6:19 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 10:17 PM
Points: 1,049, Visits: 2,957
Hi,

I am going to delete the records for last 2 years, and total number of rows 31935523..

Should I go for as below delete statement..

column name yyyymm - varchar datatype and nonclusted index already exists..

column name date filed - datetime and non-unique nonclusted index already exists


select ep_no,date,yyyymm, schd_shft,dayin, dayout,rtype,stype,
etype,stn_in, stn_out,updated_on, inserted_on
from CONTRACT_MUSTER
where yyyymm between '201001'and ''201006''


delete from from CONTRACT_MUSTER
where yyyymm between '201001'and ''201006'
go


delete from from CONTRACT_MUSTER
where yyyymm between '201006'and ''201012'
go

thanks
ananda
Post #1431495
Posted Friday, March 15, 2013 6:51 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
How big your table is? Or, better way, how many records will stay in the table after purge of records for the last two years?
You might find, that moving the records you want leave into new table, then dropping the original one and renaming new one back to the original will be much faster if the number of records to stay is less than number of records to be removed.
(You will need to remove FK constraints if any ...)



_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1431509
Posted Friday, March 15, 2013 7:46 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 6:41 AM
Points: 23,081, Visits: 31,621
You may also want to read this: http://www.sqlservercentral.com/articles/T-SQL/67898/.

There have also been several other similar articles written recently on SSC, just do a search on deleting large number of rows.



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)
Post #1431539
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse