Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I know that this is an awful thing to do for many reasons, but I am in Get Things Done mode and we have a piece of software, which we can't modify, that writes records to a table. Some of these records, for business reasons, we don't want in this table. I was thinking I could write a trigger that "aborts" any of these rows without throwing an error (so that the application doesn't fail in the front end, we want it to think it did its thing). I am intimately familiar with this application and know it won't cause any ugly side effects, we just can't modify it to behave the way we need it to.

So, is this possible, and if not, what would be another way to go about it? I thought about having some sort of Job that routinely cleans the table for records that we don't want, but I would rather for these records to never be there to begin with so there's no degree of "dirtiness" at any one time in the table.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

The only way for a trigger on a table to prevent an INSERT operation from completing is to throw an error.

It is, as you have stated, a huge hack, but you could

  • Rename the table
  • Create a view that has the same name as the original table
  • Create an instead of trigger on that view that only does an INSERT on the table if you want the row to be persisted. Otherwise, the trigger would do nothing.

That should work so long as the application isn't doing a MERGE into the table. Of course, it's a hack upon a hack so it's definitely not going to win any awards for clean code.

share|improve this answer

You could also use Virtual Private Database to hide these rows from users before they are cleaned.

share|improve this answer
It would be nice if you added some detail about what Virtual Private Databases are, and how this solves the problem at hand, without the user having to visit a link. – Max Vernon Sep 13 '12 at 13:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.