As the name suggests these are the triggers which execute on DML events or say depend on DML statements such as Update, Insert or Delete. Using DML trigger you can control the behavior of your DML statements. [Click Here To Tweet This]
Since the theory has already been discussed in the previous tutorial hence I won’t bore you further. You can refer to the previous tutorial “Introduction to Triggers” anytime.
I have created this table with the name SUPERHEROES which has only one column sh_name with data type varchar2 and data width 15. Now I will write a DML trigger which will work on this table.
So the table is created. Now let’s do some examples which will help you in understanding the concepts more clearly.
Before that a simple tip: Always remember to set your server output ON otherwise the output message returned from your trigger will not be displayed back to you.
On successfully compiling, this trigger will show you a string along with the user name who performed the “Insert” DML on superheroes table. Thus you check this trigger by Inserting a row in Superheroes table.
On successfully compiling, this trigger will print a user defined string with the username of the user who updated the row. You can check this trigger by writing an update DML on the superheroes table.
You can check the working of this trigger by executing a DELETE DML on underlying table which is superheroes.
Above three examples showed you 3 different triggers for 3 different DML events on one table. Don’t you think that if we can cover all these 3 events in just 1 trigger then it will be a great relief? If you think so then my dear friend I have some good news for you. Let me show you how we can achieve this feat.
Using this one trigger you can achieve the same results as that of the above three triggers. I have explained every single line of this trigger along with the other three triggers in detail in my Video tutorial. I highly suggest you to watch that tutorial.
Hope you enjoyed reading and learnt something. I request you to share this article with your friends via Twitter, Facebook or any means you prefer. Thanks & have a great day!
You can DOWNLOAD SQL script and presentation used in the Video and in this article.