Click to See Complete Forum and Search --> : Is it possible to dynamically remove data from a table?


memerson
11-17-2009, 06:35 AM
Hello everyone :)

I'd like to know if it is possible to be able to remove dormant data from a table dynamically? I have a table in my database which is for reserved tickets that are on sale on a site, but they will only be needed in there for about 10 minutes (which is the reserve time before they go back on sale) and I'd like to be able to get those entries deleted as they would no longer be needed and would just take up space in the table.

The time will be logged in the table using the NOW() command plus 10 minutes, so I'm assuming that there is a way to query the database to check for expired times and then delete them?

If anyone knows of how and if this is possible, I would be grateful for any help.

Thanks
Michael

ssystems
11-17-2009, 09:11 AM
SELECT * FROM Table WHERE your_date_field <= NOW()

yamaharuss
11-17-2009, 12:41 PM
If you are using MSSQL Server...

SELECT * FROM Table WHERE your_date_field <= '" & NOW() & "'

ssystems
11-17-2009, 02:09 PM
If you are using MSSQL Server...

SELECT * FROM Table WHERE your_date_field <= '" & NOW() & "'

That's for ASP if I'm not mistaken. Fr MSSQL it should be


SELECT * FROM Table WHERE your_date_field <= GETDATE()

yamaharuss
11-17-2009, 02:12 PM
I was assuming the query was running from a web page. If so, and using MSSQL, the date field required single quotes.

memerson
11-23-2009, 05:58 AM
Thanks for your help :) The NOW() did the trick.