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 7,2000
»
T-SQL
»
delete records
13 posts, Page 1 of 2
1
2
»»
delete records
Rate Topic
Display Mode
Topic Options
Author
Message
kumar99ms
kumar99ms
Posted Wednesday, August 20, 2008 4:42 AM
Valued Member
Group: General Forum Members
Last Login: Wednesday, November 25, 2009 4:57 PM
Points: 74,
Visits: 550
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,
Post #555650
karthik M
karthik M
Posted Wednesday, August 20, 2008 4:56 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 2:56 AM
Points: 2,008,
Visits: 2,469
TRUNCATE may help for your need.
before half an hour,…
You have to frame your question better. Also please post your requirement clearly.
karthik
Post #555657
Andras Belokosztolszki
Andras Belokosztolszki
Posted Wednesday, August 20, 2008 4:58 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, January 26, 2012 5:26 AM
Points: 1,367,
Visits: 1,585
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
Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
Post #555659
SuperDBA-207096
SuperDBA-207096
Posted Wednesday, August 20, 2008 4:58 AM
UDP Broadcaster
Group: General Forum Members
Last Login: Wednesday, January 02, 2013 12:15 PM
Points: 1,443,
Visits: 711
truncate won't work if you are only trying to delete some of the records... it will empty the table completely.
Post #555660
Andras Belokosztolszki
Andras Belokosztolszki
Posted Wednesday, August 20, 2008 5:00 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, January 26, 2012 5:26 AM
Points: 1,367,
Visits: 1,585
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
Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
Post #555663
karthik M
karthik M
Posted Wednesday, August 20, 2008 5:00 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 2:56 AM
Points: 2,008,
Visits: 2,469
Mark,
you are right. But OP mentioned like
Query to delete, all the records from a table
Thats why i preferred TRUNCATE.
karthik
Post #555664
karthik M
karthik M
Posted Wednesday, August 20, 2008 5:08 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 2:56 AM
Points: 2,008,
Visits: 2,469
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
Post #555672
Tom Brown
Tom Brown
Posted Wednesday, August 20, 2008 5:10 AM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 5:16 AM
Points: 1,196,
Visits: 1,319
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
Post #555674
Andras Belokosztolszki
Andras Belokosztolszki
Posted Wednesday, August 20, 2008 5:17 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, January 26, 2012 5:26 AM
Points: 1,367,
Visits: 1,585
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
Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
Post #555678
Amit Khanna-455738
Amit Khanna-455738
Posted Wednesday, August 20, 2008 5:35 AM
SSC Journeyman
Group: General Forum Members
Last Login: Friday, April 13, 2012 6:25 AM
Points: 89,
Visits: 221
Hi kumar99ms ,
Can you please elaborate your question clearly?
Thanks,
Amit Khanna
Post #555685
« Prev Topic
|
Next Topic »
13 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.