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 2005
»
T-SQL (SS2K5)
»
delete table
delete table
Rate Topic
Display Mode
Topic Options
Author
Message
kumar99ms
kumar99ms
Posted Wednesday, August 20, 2008 4:37 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 #555645
Dugi
Dugi
Posted Wednesday, August 20, 2008 4:42 AM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 1:48 AM
Points: 1,252,
Visits: 3,367
no you can not do such a thing... you should save the script for deleting also with parameter that identify the condition and after that you will do schedule the job to do it for example after 30 min!
============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #555649
Johannes Fourie
Johannes Fourie
Posted Wednesday, August 20, 2008 4:59 AM
SSC Journeyman
Group: General Forum Members
Last Login: 2 days ago @ 9:16 AM
Points: 77,
Visits: 210
Do you have a DATETIME column on the table? You would need it to delete rows older than 30 minutes. To do that you can use the DATEADD function in your where clause.
DELETE FROM dbo.YourTable WHERE Condition=100 AND YourTimeColumn < DATEADD(MINUTE, -30, GETDATE())
Post #555662
arjun.tewari
arjun.tewari
Posted Wednesday, August 20, 2008 5:03 AM
SSC Journeyman
Group: General Forum Members
Last Login: Thursday, June 03, 2010 7:25 AM
Points: 75,
Visits: 186
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,
I am afraid your question is not clear. What do you want? You want to delete all the records older than 30 mins or you want the delete statement should be fired after 30 mins?
Post #555668
Dugi
Dugi
Posted Wednesday, August 20, 2008 5:08 AM
Ten Centuries
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 1:48 AM
Points: 1,252,
Visits: 3,367
Ok the ideas are here and if you want to clearly solution you must post the table definition and some sample data just to do the things correct!
============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #555673
kumar99ms
kumar99ms
Posted Wednesday, August 20, 2008 5:10 AM
Valued Member
Group: General Forum Members
Last Login: Wednesday, November 25, 2009 4:57 PM
Points: 74,
Visits: 550
hi every body
Thanks u for your effor
I want a query for delete every half an hour.
my condition is i am not schedule an job for this i am not use any Truncate also
Could plz any query using sysdate time or datetime for this plz help me
Post #555675
arjun.tewari
arjun.tewari
Posted Wednesday, August 20, 2008 5:37 AM
SSC Journeyman
Group: General Forum Members
Last Login: Thursday, June 03, 2010 7:25 AM
Points: 75,
Visits: 186
you can not do this using SQL. You will have to either schedule a job to do this or create a Windows Service which will fire the delete query every half-an-hour
Post #555687
Johannes Fourie
Johannes Fourie
Posted Wednesday, August 20, 2008 5:51 AM
SSC Journeyman
Group: General Forum Members
Last Login: 2 days ago @ 9:16 AM
Points: 77,
Visits: 210
Another option would be to do the delete on an insert trigger, it would add additional overhead on the table, but if the table does not have too much activity then it should be fine. So the table with the trigger would constantly maintain itself. On the one hand it creates additional overhead, but the deletes will be done over smaller data sets because it may be executed more frequently, so it may even out.
You would still need a column that has the creation time of each record.
Post #555694
arjun.tewari
arjun.tewari
Posted Wednesday, August 20, 2008 6:01 AM
SSC Journeyman
Group: General Forum Members
Last Login: Thursday, June 03, 2010 7:25 AM
Points: 75,
Visits: 186
Johannes Fourie (8/20/2008)
Another option would be to do the delete on an insert trigger, it would add additional overhead on the table, but if the table does not have too much activity then it should be fine. So the table with the trigger would constantly maintain itself. On the one hand it creates additional overhead, but the deletes will be done over smaller data sets because it may be executed more frequently, so it may even out.
You would still need a column that has the creation time of each record.
Hey Johannes
This fella wants to remove all the data from after every thirty minute. After every thirty minute, a query should execute and remove all the data from the table.
Post #555701
« Prev Topic
|
Next Topic »
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.