SQLTeam.com | Weblogs | Forums

How to write a trigger autorun in database?

sql2008

#1

Hello everybody.I refer a lot of link, and the trigger will bean insert, update, delete.

Now, I wan to a trigger autorun day by day in a table.
Example : Table PRODUCT

ID	Cost	ExpDate
C1	10	2015-06-01
C2	15	2016-06-01
C3	12	2015-07-01
C4	15	2015-08-01
C5	10	2016-01-01

Ok, I want to check ExpDate , if it smaller today, auto delete record in table PRODUCT.
Everyday,it checks the current date compared with the date in the table PRODUCT, if the date is greater than deleting rows in table PRODUCT.It will run underground in the database
Everybody have ideas about this, share with me.Thank you


#2

You will need a job . See SQL Server Agent .
Here you can configure a job to run once a day (or how often you want) , job that will run , for example, a dedicated stored procedure.