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 table Expand / Collapse
Author
Message
Posted Wednesday, August 20, 2008 4:37 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued 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
Posted Wednesday, August 20, 2008 4:42 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, November 20, 2014 3:44 AM
Points: 1,260, Visits: 3,424
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
Posted Wednesday, August 20, 2008 4:59 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, July 18, 2014 7:04 AM
Points: 77, Visits: 223
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
Posted Wednesday, August 20, 2008 5:03 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 3, 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
Posted Wednesday, August 20, 2008 5:08 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, November 20, 2014 3:44 AM
Points: 1,260, Visits: 3,424
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
Posted Wednesday, August 20, 2008 5:10 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued 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
Posted Wednesday, August 20, 2008 5:37 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 3, 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
Posted Wednesday, August 20, 2008 5:51 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, July 18, 2014 7:04 AM
Points: 77, Visits: 223
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
Posted Wednesday, August 20, 2008 6:01 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 3, 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 »

Add to briefcase

Permissions Expand / Collapse