After searching the internet I found several tutorials on the subject, but what is still unclear to me is when to use a trigger and when a stored procedure.
Thank you very much for any possible guidance !!!
Sincerely,
Miguel Angel
After searching the internet I found several tutorials on the subject, but what is still unclear to me is when to use a trigger and when a stored procedure.
Thank you very much for any possible guidance !!!
Sincerely,
Miguel Angel
The main difference between triggers and stored procedures: It is that triggers are procedures that are executed automatically, when an event occurs on which you want to work. For this there are three types of events that can trigger a trigger: INSERT, DELETE and UPDATE. The trigger is programmed to perform a specific task that must be done whenever one of the aforementioned events occurs. It does not require human or programmatic intervention and can not be stopped. It has some characteristics:
A stored procedure is a stored procedure that must be invoked to execute.
-------------
In summary, if you are going to perform an audit of the tables in your database, use triggers. If you want to use stored procedures it can be to get a list of clients. This action will be repeated in the system but the work is done directly by the database
A trigger (in English) as its name says triggers when an event occurs in the database, such as an INSERT or a DELETE. Triggers are created and you do not need to call them to run, they simply run with the requirement that you have established. For example, you make a trigger that when an UPDATE is made in the database in a field, the trigger is executed and INSERT in another table with the old values.
On the other hand, a procedure is like a function that you create and you can call from another site to use it as you want. You can have a procedure that tells you how many times it appears on behalf of the students that you pass as a parameter. And every time you call him he will do that. It does not run just like a trigger.
I hope I helped you and explained myself well. Greetings.