Last post Oct 21, 2016 08:10 PM by Nasser Malik
Oct 21, 2016 05:51 PM|Sandeep Apsingekar|LINK
I have a table which has three columns UID, Created Date and time, Last Login Date and Time. Is there a way where I can delete a record automatically after 24 hours of its creation and Last Login Date and Time.
I'm able to insert the Last Login Date and time, Created Date and Time with ASP.NET. So, now I want a query where I can delete it after 24 hours of its creation and Login.
Any help would be appreciated.
Oct 21, 2016 06:07 PM|senthilwaits|LINK
You can do that with
SQL Server Agent. Simply create a job with a regular schedule and the SQL you want to run. There is an easy to use wizard interface for job creation.
Oct 21, 2016 06:32 PM|Sandeep Apsingekar|LINK
Thank you very much, I really appreciate it for responding back to me quickly.
So, to have access with SQL Server Agent do I need to login with SQL Server Authentication? Because when I log in with Windows Authentication I do not see SQL Server Agent.
I also wrote a stored procedure for deleting the record.
Oct 21, 2016 06:50 PM|senthilwaits|LINK
I think the problem is not with the login. You may be using SQL Server Express and that doesn't include SQL Server Agent, so it's not possible to just create SQL Agent jobs.
when you run
select serverproperty('edition') and if returns Express edition, you have to upgrade to get SQL Server Agent
Refer this for an
Oct 21, 2016 08:10 PM|Nasser Malik|LINK
You can put your code in console and attach the exe to windows scheduler which can run it after some interval.
You can make a windows service which can call the database to do the job
You can use SQL server Schedule Job.
You can use
timer class to run your function on regular interval. Put this in global.asax application_start() to call a function on regular basis. But this is not a recommended approach as application pool can be reset at any time. And your code will not run if you
app idle for longer period.
Sharing some links which surely can help