August 20, 2008 at 4:42 am
Query to delete, all the records from a table before half an hour,…
Delete * from table where condition=100 and …..what we have write here…for time…
Regards,
August 20, 2008 at 4:56 am
TRUNCATE may help for your need.
before half an hour,…
You have to frame your question better. Also please post your requirement clearly.
karthik
August 20, 2008 at 4:58 am
kumar99ms (8/20/2008)
Query to delete, all the records from a table before half an hour,…Delete * from table where condition=100 and …..what we have write here…for time…
Regards,
What is the schema of your table? Could you list us the columns that contain the time information? If you have nothing in the table to keep track of the time information, then you will not be able to do this, and will need to rely on your backups (there is point in time recovery in the enterprise edition of SQL Server, so you could restore the information as of half an hour ago into a separate database)
Another thing to do: first use a select statement to see if the rows deleted are the rows you indeed want to delete.
Regards,
Andras
August 20, 2008 at 4:58 am
truncate won't work if you are only trying to delete some of the records... it will empty the table completely.
August 20, 2008 at 5:00 am
karthikeyan (8/20/2008)
TRUNCATE may help for your need.You have to frame your question better. Also please post your requirement clearly.
While I agree with Karthik that TRUNCATE may help you, it would probably be a poor choice if you do not want to get rid of every row in your table. Since you specify a where clause, TRUNCATE is likely not what you are looking for.
Regards,
Andras
August 20, 2008 at 5:00 am
Mark,
you are right. But OP mentioned like
Query to delete, all the records from a table
Thats why i preferred TRUNCATE.
karthik
August 20, 2008 at 5:08 am
Andras,
t would probably be a poor choice if you do not want to get rid of every row in your table.
You mean we need to use TRUNCATE if we dont want the log for those deleted records.
Am i correct ?
Since you specify a where clause, TRUNCATE is likely not what you are looking for.
Yes, He has to use DELETE.
karthik
August 20, 2008 at 5:10 am
On first reading I thought your delete was taking over half an hour - so TRUNCATE may be an answer instead of DELETE * for a particularly large table.
However I'm guessing you really mean you want to delete records older than half an hour, in which case you'll need something like this
DELETE FROM table
WHERE dateColumn < DATEADD(mi, -30, GetDate())
you will need a suitable dateColumn containing the records creation time
August 20, 2008 at 5:17 am
karthikeyan (8/20/2008)
Andras,t would probably be a poor choice if you do not want to get rid of every row in your table.
You mean we need to use TRUNCATE if we dont want the log for those deleted records.
Am i correct ?
...
Hi Karthik,
Basically yes, when you can use TRUNCATE, it is a good way to empty the whole table, and the individual row deletes will not be in the transaction log, so it will be fast. But TRUNCATE deletes all the rows, and this is the reason it may be less applicable to the OP (assuming I understood the question right).
Regards,
Andras
August 20, 2008 at 5:35 am
Hi kumar99ms ,
Can you please elaborate your question clearly?
Thanks,
Amit Khanna
June 8, 2012 at 2:33 pm
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
June 9, 2012 at 9:05 am
adhiman (6/8/2012)
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%5B/quote%5D
This isn't necessarily correct. DELETE does not necessarily (and frequently doesn't) block anything.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 9, 2012 at 9:07 am
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 [font="Arial Black"]before half an hour[/font],…
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply