Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trigger

Author  Topic 

pradeep_iete
Yak Posting Veteran

84 Posts

Posted - 2008-05-30 : 11:17:56
Hi all,
How can i write a trigger that will delete the record once it went 24 hour old after its insertion.
Is it possible on the first place? If yes please guide me.

ibeckett
Starting Member

12 Posts

Posted - 2008-05-30 : 11:35:39
You can write a simple T-SQL script or stored procedure to delete the rows that are older than 24 hours. Something like (replace RowDate example with your own time stamp column name)...


-- delete all rows where the RowDate
-- is 24 or more hours older than the current date
DELETE Table
WHERE RowDate <= dateadd(hour,-24,getdate())



If you are using SQL 2005 and have the proper access then you can then call the script/procedure from a scheduled job using SQL Server Agent

In management studio: SQL Server Agent -> Jobs -> New Job





Ian Beckett
ibeckett at gmail dot com
www.sqlblog.ibeckett.com
Go to Top of Page

pradeep_iete
Yak Posting Veteran

84 Posts

Posted - 2008-05-31 : 11:40:12
Thanx,

I wud still like to know that how shud we use trigger to delete the records.

cud yoou elaborrate on Job sheduling part to acheive the deletion.I need it urgently




Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-31 : 13:01:23
Refer this:-

http://msdn.microsoft.com/en-us/library/ms191439.aspx
Go to Top of Page
   

- Advertisement -