简体   繁体   中英

How to create a trigger to delete a record

Looking for ideas on how to write a trigger that will delete a record when a condition is met.

I have some records being written to a SQL Server 2008 database table. These records that are being written are not important and I would like to see them removed. There are two columns that will have unique information when these records are written and I would like a trigger to remove them as soon as they are written.

I could run a daily job to delete all records that equal X and Y but my thought why not delete the records as they are written.

What would this kind of trigger look like?

If you are not able to change that at any app layer you can use an INSTEAD OF INSERT trigger and those rows will not even be inserted at all.

It will save the database from both inserting and deleting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM