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 ««12

delete records Expand / Collapse
Author
Message
Posted Friday, June 08, 2012 2:33 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 12, 2013 10:40 AM
Points: 7, Visits: 98
If you want to do a quick one then
Create another table with same structure and insert the rows that you don't want to delete into the other table.
Now truncate the original table .Now the second table has all the rows you want. Now switch the names.

This way you won't block others because you are not performing any big transaction.
I have an article that is worth trying if you want to perform deletes efficiently.
Let me know if you have questions

http://tsqltips.blogspot.com/2012/06/deleting-records-from-sql-table.html
Post #1313394
Posted Saturday, June 09, 2012 9:05 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:03 PM
Points: 35,954, Visits: 30,243
adhiman (6/8/2012)
If you want to do a quick one then
Create another table with same structure and insert the rows that you don't want to delete into the other table.
Now truncate the original table .Now the second table has all the rows you want. Now switch the names.

This way you won't block others because you are not performing any big transaction.
I have an article that is worth trying if you want to perform deletes efficiently.
Let me know if you have questions

http://tsqltips.blogspot.com/2012/06/deleting-records-from-sql-table.html


This isn't necessarily correct. DELETE does not necessarily (and frequently doesn't) block anything.



--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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1313498
Posted Saturday, June 09, 2012 9:07 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:03 PM
Points: 35,954, Visits: 30,243
karthikeyan-444867 (8/20/2008)
Mark,

you are right. But OP mentioned like

Query to delete, all the records from a table


Thats why i preferred TRUNCATE.


But that's only a part of what the OP wants. You cut off the other very important part that makes TRUNCATE the wrong choice in this case...

Query to delete, all the records from a table before half an hour,…


--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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1313500
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse