0

I want to create dynamic triggers in java. Before executing an insert/delete/update i will create the trigger with the correct data it needs to work on and after the insert/delete/update is finished i will drop the trigger.

Is it okay to drop and recreate triggers dynamically through the application? If so what is the risk?

1 Answer 1

1

You could create triggers dynamically but I don't know why you would. If your calling application is completely aware of what data needs to be manipulated, then why not just let your calling application make the database updates?

Triggers are when you ALWAYS want something to happen to your data, everytime that data is updated, inserted, or deleted. That's not what you want. You are just trying to run a statement once. Better to do that in your application.

Sign up to request clarification or add additional context in comments.

2 Comments

Your'e absolutely right. but lets say I need to delete n number of items from one table which will always follow by deleting n number of items from other tables. Will creating a trigger each time with the correct n number before the initial delete is okay? and dropping it of course after completion?
No. Triggers aren't created with "Delete N records". Triggers have access to the data that is deleted and can then join those records to other tables if you also want them deleted. But again, if YOU are in control of what's being deleted from one table, why wouldn't you just ALSO delete from the other tables in your application? Triggers are NOT a good solution for that problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.