{"id":339,"date":"2020-12-07T14:48:39","date_gmt":"2020-12-07T09:18:39","guid":{"rendered":"http:\/\/sumitjangid.com\/?p=339"},"modified":"2020-12-07T15:57:32","modified_gmt":"2020-12-07T10:27:32","slug":"triggers","status":"publish","type":"post","link":"http:\/\/sumitjangid.com\/index.php\/2020\/12\/07\/triggers\/","title":{"rendered":"Triggers"},"content":{"rendered":"\n<p>Triggers are specail stored procedures that execute automatically based on an event. <\/p>\n\n\n\n<p>There are 3 types of triggers:<\/p>\n\n\n\n<ol><li>DML (Data-Manipulating Language) Triggers: work when the event of DMLs are invoked like Insertion, Updating, Deletion etc<\/li><li>DDL (Data-Definition Language) Triggers: works when the events of DDL are invoked like Create, Drop, Alter etc<\/li><li>Logon triggers: works when the event of logging in and Logging out are invoked.<\/li><\/ol>\n\n\n\n<p>DML Triggers will be implemented as below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TRIGGER &#91;schema_name.]trigger_name\r\nON table_name\r\nAFTER  {&#91;INSERT],&#91;UPDATE],&#91;DELETE]}\r\n&#91;NOT FOR REPLICATION]\r\nAS\r\n{sql_statements}<\/code><\/pre>\n\n\n\n<p>At the place of after in the above example following can be used:<\/p>\n\n\n\n<ol><li>After: Event will be triggered after the insert is done<\/li><li>Before: Event will be triggered before the insert is done<\/li><li>Instead of: this will skip the insert and perform the given instructions. this is like a function override for insert or what ever you will use.<\/li><\/ol>\n\n\n\n<p>DDL Triggers will be implemented as below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TRIGGER alert_table\r\nON Database\r\nFOR CREATE_TABLE, DROP_TABLE, ALTER_TABLE\r\nAS\r\n  insert into logs values('Table Created'); <\/code><\/pre>\n\n\n\n<p>To Disable a trigger:<\/p>\n\n\n\n<p>User Disable trigger &lt;Trigger name> on Database.table name<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Triggers are specail stored procedures that execute automatically based on an event. There are 3 types of triggers: DML (Data-Manipulating Language) Triggers: work when the event of DMLs are invoked like Insertion, Updating, Deletion etc&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"_links":{"self":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/339"}],"collection":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/comments?post=339"}],"version-history":[{"count":4,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/339\/revisions"}],"predecessor-version":[{"id":343,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/339\/revisions\/343"}],"wp:attachment":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/categories?post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/tags?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}