Delete records after certain period
-
I have a table which requires records to be deleted programmatically at time intrvals. I have an created field which stores the time it was created and I can't figure out how to delete records older than 3 hours. ie:
DELETE FROM temp WHERE created < now()+(3600*3)
I'm using mysql BTW, but I don't think SQL or SQL would have much discrepancies here would they? Thanks for you time :) "Two wrongs don't make a right, but three lefts do!" - Alex Barylski :) -
I have a table which requires records to be deleted programmatically at time intrvals. I have an created field which stores the time it was created and I can't figure out how to delete records older than 3 hours. ie:
DELETE FROM temp WHERE created < now()+(3600*3)
I'm using mysql BTW, but I don't think SQL or SQL would have much discrepancies here would they? Thanks for you time :) "Two wrongs don't make a right, but three lefts do!" - Alex Barylski :)DELETE FROM temp WHERE created <= DATEADD( h, CURDATE(), -3); This will work for SQL Server, but I'm not sure about MySQL. Give it a shot :)
-
I have a table which requires records to be deleted programmatically at time intrvals. I have an created field which stores the time it was created and I can't figure out how to delete records older than 3 hours. ie:
DELETE FROM temp WHERE created < now()+(3600*3)
I'm using mysql BTW, but I don't think SQL or SQL would have much discrepancies here would they? Thanks for you time :) "Two wrongs don't make a right, but three lefts do!" - Alex Barylski :)this solution can work for SQL Server: DELETE FROM temp WHERE DATEDIFF(Hour,created,getdate()) > 3