Quantcast
Channel: Alternative to Dynamic SQL inside trigger? - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 2

Answer by Rick James for Alternative to Dynamic SQL inside trigger?

$
0
0

If the list things to check is constant, then spell them out rather than constructing the tests. (not viable)

But, presumably that is not the case...

Plan A: Replace the INSERT that needs to call the trigger with a PROCEDURE call. The routine contains the INSERT plus the rest of the code you presented.

Plan B: As with Plan A, but do it in application code.

Note: Either A or B would be wrapped in BEGIN...COMMIT to make it 'atomic'.

Bottom Line: Triggers can't do everything.

Enforcement of A (I think this will prevent other from bypassing the stored proc.)

  • CREATE USER special@... ... -- a new user
  • GRANT INSERT ON db.tbl TO special@... -- let it get in
  • The stored proc would be SECURITY special@... -- to run proc as "special" so it can do the INSERTs
  • Remove INSERT PRIVILEGE for that table from others. (This gets messy, or maybe unnecessary.) (It may help if the table is in a separate database that no one currently has access to.)
  • (My gut says there is one more step. I'll leave it as a 'exercise for the reader'.)

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>