Question

I am using asp.NET C# and I have a table in SQL server 2005 database. Once a student clicks a specific button in the application interface, the student id that will be taken from the session should be stored in the StudentID attribute. At a specific time (for example: at 9:00 A.M) I want to delete the table records automatically. It will be better if I could be able to archive these deleted records somewhere. I searched in Google and I found that I have to make a log trigger, but I am not sure if it will be the best solution in my situation where I want to delete the table records twice a day (in two different hours)!!

Actually I never use the trigger but I read that it used to delete records in someway.

Any help regarding deleting the table records in SQL server 2005 database will be appreciated..

Thanks.

No correct solution

OTHER TIPS

A regular SQL trigger should work fine:

create trigger FooDeleteTrigger on Foo
after delete
as
insert FooArchive (...columns...)
select ...columns...
from deleted

Alternatively, all in one command:

delete from Foo
output deleted.col1, deleted.col2, ...
into FooArchive
--where clause as needed, etc

Write a stored procedure to delete the records from the table and in the same SP write statements to insert the deleted record in your archive table. You can use deleted keyword to access the deleted rows from the table. Now once you are done writing the SP create a job in SQL Server on this SP and schedule it as per your requirement.

Alternatively you can only put the deletion logic in the stored procedure and move the insertion-to-archive-table logic to trigger developed on the main table.

Check this out for your reference: http://technet.microsoft.com/en-us/library/ms177564.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top