{"id":230,"date":"2018-07-19T09:37:38","date_gmt":"2018-07-19T09:37:38","guid":{"rendered":"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=230"},"modified":"2018-08-01T11:05:43","modified_gmt":"2018-08-01T11:05:43","slug":"active-database","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/chapter\/active-database\/","title":{"rendered":"Active Database"},"content":{"raw":"<div>\r\n\r\n<strong>Syntax for creating triggers in SQL<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify\">\u00a0<strong>Trigger name <\/strong>- unique within one database schema<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0<strong>Timing <\/strong>- depends on the order of controlled events (before or after or instead of)<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0<strong>Triggering event <\/strong>- event which fires the trigger<strong> (E)<\/strong><\/li>\r\n \t<li style=\"text-align: justify\">\u00a0<strong>Filtering condition <\/strong>- checked when the triggering event occurs<strong> (C)<\/strong><\/li>\r\n \t<li style=\"text-align: justify\">\u00a0<strong>Target <\/strong>- table (or view) against which the trigger is fired; they should be both created within the same schema<\/li>\r\n \t<li style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span><strong style=\"text-align: initial;font-size: 1em\">Trigger Parameters <\/strong><span style=\"text-align: initial;font-size: 1em\">- parameters used to denote the record columns; preceded by colon<\/span><strong style=\"text-align: initial;font-size: 1em\">:new, :old for new and old versions of the values respectively<\/strong><\/li>\r\n \t<li style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0Trigger action <\/strong><span style=\"text-align: initial;font-size: 1em\">- SQL statements, executed when the trigger fires; surrounded by <\/span><strong style=\"text-align: initial;font-size: 1em\">Begin<\/strong><span style=\"text-align: initial;font-size: 1em\"> ... <\/span><strong style=\"text-align: initial;font-size: 1em\">End (A)\u00a0\u00a0<\/strong><\/li>\r\n<\/ul>\r\n<\/div>\r\n<div style=\"text-align: justify\">\r\n\r\n\u00a0 CREATE [OR REPLACE] TRIGGER <em>trigger_name<\/em>\r\n\r\n<em>timing event1 [<\/em>OR<em> event2 <\/em>OR<em> event3] <\/em>ON <em>table_name<\/em>\r\n\r\nBEGIN\r\n\r\n<em>SQL statements;<\/em>\r\n\r\nEND;\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0The trigger body consisting of <\/span><em style=\"text-align: initial;font-size: 1em\">SQL statements<\/em><span style=\"text-align: initial;font-size: 1em\"> will be executed only <\/span><strong style=\"text-align: initial;font-size: 1em\"><em>once <\/em><\/strong><span style=\"text-align: initial;font-size: 1em\">according to the prescribed <\/span><em style=\"text-align: initial;font-size: 1em\">timing<\/em><span style=\"text-align: initial;font-size: 1em\">, when the <\/span><em style=\"text-align: initial;font-size: 1em\">event1 (event2, event3) <\/em><span style=\"text-align: initial;font-size: 1em\">occurs against the monitored table in question<\/span><em style=\"text-align: initial;font-size: 1em\"> table_name.<\/em><\/p>\r\n<em>\u00a0<\/em>\r\n<div>\r\n<p style=\"text-align: center\"><img class=\" wp-image-232 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110.png\" alt=\"\" width=\"645\" height=\"366\" \/><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 Syntax for Creating Row Triggers<\/strong>\r\n\r\n&nbsp;\r\n\r\nCREATE [OR REPLACE] TRIGGER <em>trigger_name<\/em>\r\n\r\n<em>timing event1 [<\/em>OR<em> event2 <\/em>OR<em> event3] <\/em>ON <em>table_name<\/em>\r\n\r\n[REFERENCING OLD AS <em>old |<\/em> NEW AS <em>new<\/em>]\r\n\r\nFOR EACH ROW\r\n\r\n[WHEN <em>condition<\/em>]\r\n\r\nBEGIN\r\n\r\n<em>SQL statements;<\/em>\r\n\r\nEND\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The trigger body consisting of <em>SQL statements<\/em> will be executed once <strong><em>for each row<\/em><\/strong> affected by <em>event1<\/em> (<em>event2<\/em>, <em>event3<\/em>) in the table named <em>table_name<\/em> subject to the additional <em>condition<\/em>.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 SQL&gt;CREATE OR REPLACE TRIGGER derive_commission_trg <\/strong>\r\n\r\n<strong>2 BEFORE UPDATE OF sal ON emp<\/strong>\r\n\r\n<strong>3 FOR EACH ROW\u00a0<\/strong>\r\n\r\n<strong>4 WHEN (new.job = 'SALESMAN')<\/strong>\r\n\r\n<strong>5\u00a0 <\/strong><strong>BEGIN<\/strong>\r\n\r\n<strong>6\u00a0\u00a0<\/strong><strong>:new.comm := :old.comm * (:new.sal\/:old.sal);<\/strong>\r\n\r\n<strong>\u00a0<\/strong><strong>7\u00a0 <\/strong><strong>END;<\/strong>\r\n\r\n<strong>8\u00a0<\/strong>\r\n<p style=\"text-align: center\"><img class=\"wp-image-233 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111.png\" alt=\"\" width=\"549\" height=\"194\" \/><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n<div>\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Trigger Execution Order\r\n\r\n&nbsp;\r\n\r\n1.\u00a0\u00a0\u00a0 Execute all BEFORE STATEMENT triggers.\r\n\r\n2.\u00a0\u00a0\u00a0 Disable temporarily all integrity constraints recorded against the table.\r\n\r\n3.\u00a0\u00a0\u00a0 Loop for each row in the table.\r\n<ul>\r\n \t<li>\u00a0 Execute all BEFORE ROW triggers.<\/li>\r\n \t<li>\u00a0 Execute the SQL statement against the row and perform integrity constraint checking of the data.<\/li>\r\n \t<li>\u00a0 Execute all AFTER ROW triggers.<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\n4. Complete deferred integrity constraint checking against the table.\r\n\r\n5. Execute all AFTER STATEMENT triggers.\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Controlling Triggers using SQL<\/span>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 Disable\/Re-enable database trigger<\/strong>\r\n\r\nALTER TRIGGER trigger_name\u00a0 DISABLE | ENABLE\r\n\r\n<strong>Disable or Re-enable all triggers for table<\/strong>\r\n\r\nALTER TABLE <em>table_name DISABLE<\/em> | <em>ENABLE<\/em> ALL TRIGGERS\r\n\r\n<strong>Removing a trigger from database<\/strong>\r\n\r\nDROP TRIGGER trigger_name\r\n\r\n<\/div>\r\n<strong><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Using Database Triggers<\/span><\/strong>\r\n<div>\r\n\r\n\u00a0 \u00a0 \u00a0\u00a0<strong>Auditing Table Operations<\/strong>\r\n\r\neach time a table is accessed auditing information is recorded against it\r\n\r\n&nbsp;\r\n\r\n<strong>Tracking Record Value Changes<\/strong>\r\n\r\neach time a record value is changed the previous value is recorded\r\n\r\n&nbsp;\r\n\r\n<strong>Protecting Database Referential Integrity: <\/strong>if foreign key points to changing records\r\n\r\nreferential integrity must be maintained\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 Maintenance of Semantic Integrity<\/strong>\r\n\r\n<strong>e.g. <\/strong>when the factory is closed, all employees should become unemployed\r\n\r\n&nbsp;\r\n\r\n<strong>Storing Derived Data<\/strong>\r\n\r\n<strong>\u00a0e.g. <\/strong>the number of items in the trolley should correspond to the current session selection\r\n\r\n<strong>Security Access Control<\/strong>\r\n\r\n<strong>\u00a0e.g. <\/strong>checking user privileges when accessing sensitive information\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0<strong>Counting Statement Execution<\/strong><\/span>\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 SQL&gt;CREATE OR REPLACE TRIGGER audit_emp<\/strong>\r\n\r\n<strong>2 AFTER DELETE ON emp<\/strong>\r\n\r\n<strong>3 FOR EACH ROW<\/strong>\r\n\r\n<strong>4\u00a0 <\/strong><strong>BEGIN<\/strong>\r\n\r\n<strong>5\u00a0<\/strong><strong>UPDATE audit_table SET del = del + 1<\/strong>\r\n\r\n<strong>6\u00a0<\/strong><strong>WHERE user_name = USER<\/strong>\r\n\r\n<strong>7\u00a0<\/strong><strong>AND table_name = 'EMP\u2019;<\/strong>\r\n\r\n<strong>7\u00a0 <\/strong><strong>END;<\/strong>\r\n\r\n<strong>8\u00a0 <\/strong>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0Whenever an employee record is deleted from database, counter in an audit table registering the number of deleted rows for current user in system variable USER is incremented.<\/span><\/p>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span>\r\n\r\n<strong><span style=\"text-align: initial;font-size: 1em\">Recording Changes<\/span><\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">SQL&gt;CREATE OR REPLACE TRIGGER audit_emp_values 2 AFTER DELETE OR UPDATE ON emp<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">3 FOR EACH ROW<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">4\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">BEGIN<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">5\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">INSERT INTO audit_emp_values (user_name,<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">6\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">timestamp, id, old_last_name, new_last_name,<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">7\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">old_title, new_title, old_salary, new_salary)<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">8\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">VALUES (USER, SYSDATE, :old.empno, :old.ename,<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">9\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">:new.ename, :old.job, :new.job,<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">10\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">:old.sal, :new.sal);<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">11\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">END;<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Whenever some details for an employee are deleted or updated, both the previous and new details are recorded in an audit table to allow tracing the history of changes. An insert operation cannot be recorded with this trigger as old.empno has no value.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n<div>\r\n<p style=\"text-align: justify\"><strong><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 <\/span><\/strong><\/p>\r\n<p style=\"text-align: justify\"><strong><span style=\"text-align: initial;font-size: 1em\">Protecting Referential Integrity<\/span><\/strong><\/p>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0SQL&gt;CREATE OR REPLACE TRIGGER cascade_updates 2 AFTER UPDATE OF deptno ON dept<\/strong><\/p>\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a03 FOR EACH ROW<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">\u00a04\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">BEGIN<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">5\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">UPDATE emp<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">6<\/strong><span style=\"text-align: initial;font-size: 1em\">\u00a0\u00a0<\/span><strong style=\"text-align: initial;font-size: 1em\">SET<\/strong><span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span><strong style=\"text-align: initial;font-size: 1em\">emp.deptno = :new.deptno<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">7\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">WHERE\u00a0 emp.deptno = :old.deptno;<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">8\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">END<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">9\u00a0\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">\/<\/strong>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">\u00a0 \u00a0Whenever the department number changes, all employee records for this department will automatically be changed as well, so that the employees will continue to work for the same department.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong><span style=\"text-align: initial;font-size: 1em\">Restrictions for Database Triggers<\/span><\/strong><\/p>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: justify\"><strong>\u00a0 \u00a0 Problem: <\/strong>impossible to determine certain values during execution of a sequence of operations belonging to one and the same transaction.<\/p>\r\n<p style=\"text-align: justify\"><strong>Mutating tables: <\/strong>contain rows which change their values after certain operation and which are used again before the current transaction commits.<\/p>\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">Preventing table mutation:<\/strong>\r\n\r\n<\/div>\r\n<div>\r\n<ul>\r\n \t<li>Should not contain rows which are constrained by rows from other changing tables<\/li>\r\n \t<li>Should not contain rows which are updated and read in one and the same operation<\/li>\r\n \t<li style=\"text-align: justify\">\u00a0Should not contain rows which are updated and read via other operations during the same transaction<\/li>\r\n<\/ul>\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\"><strong>Mutating Table<\/strong><\/span>\r\n\r\n&nbsp;\r\n<div>\r\n\r\n<strong>\u00a0 \u00a0 SQL&gt; CREATE OR REPLACE TRIGGER emp_count<\/strong>\r\n\r\n<strong>2\u00a0\u00a0\u00a0 <\/strong><strong>AFTER DELETE ON emp<\/strong>\r\n\r\n<strong>3\u00a0\u00a0\u00a0 <\/strong><strong>FOR EACH ROW<\/strong>\r\n\r\n<strong>4\u00a0\u00a0\u00a0 <\/strong><strong>DECLARE<\/strong><strong>\u00a0<\/strong>\r\n\r\n<strong>5\u00a0\u00a0\u00a0\u00a0<\/strong><strong>num INTEGER;<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">6\u00a0 \u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">BEGIN<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">7\u00a0 \u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">SELECT COUNT(*) INTO num FROM emp;<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">8\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">DBMS_OUTPUT.PUT_LINE(' There are now ' || num || ' employees.');<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">9\u00a0\u00a0\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">END;<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">10\u00a0\u00a0\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">\/<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">SQL&gt; DELETE FROM emp<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">2\u00a0 WHERE\u00a0 deptno = 30;<\/strong>\r\n<div>\r\n\r\n<span style=\"text-align: justify;font-size: 1em\">\u00a0 \u00a0Under the bar is code entered in SQL-PLUS which triggers cascade_updates in this case. Triggers are not executed directly.<\/span>\r\n\r\n<\/div>\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">Mutating Table (fixed)<\/span>\r\n<div>\r\n<p style=\"text-align: center\"><strong><img class=\"alignnone size-full wp-image-234\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112.png\" alt=\"\" width=\"843\" height=\"381\" \/><\/strong><\/p>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-235 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113.png\" alt=\"\" width=\"894\" height=\"448\" \/><\/p>\r\n\r\n<\/div>\r\n<strong>\u00a0 \u00a0 Rules for Good SQL Practice<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>Rule 1:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>change data<\/em> in the primary key, foreign key, or unique key columns of any table.\r\n\r\n<strong>Rule 2:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>update records<\/em> in the same table you read during the same transaction.\r\n\r\n<strong>Rule 3:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>aggregate<\/em> over the same table you are updating.\r\n\r\n<strong>Rule 4:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>read data<\/em> from a table which is updated during the same transaction.\r\n\r\n&nbsp;\r\n\r\n<strong>\u00a0 \u00a0 \u00a0SUMMARY<\/strong>\r\n<ul>\r\n \t<li>Active DBMSs embed situation-action rules in database.<\/li>\r\n \t<li>Support many functionalities:<\/li>\r\n \t<li>E.g.:\u00a0 Integrity control,access control,monitoring,derived data,change notification.<\/li>\r\n \t<li>Some Active DBMS functionality commercially available in SQL:99 as triggers.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-236 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114.png\" alt=\"\" width=\"639\" height=\"360\" \/><\/p>","rendered":"<div>\n<p><strong>Syntax for creating triggers in SQL<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">\u00a0<strong>Trigger name <\/strong>&#8211; unique within one database schema<\/li>\n<li style=\"text-align: justify\">\u00a0<strong>Timing <\/strong>&#8211; depends on the order of controlled events (before or after or instead of)<\/li>\n<li style=\"text-align: justify\">\u00a0<strong>Triggering event <\/strong>&#8211; event which fires the trigger<strong> (E)<\/strong><\/li>\n<li style=\"text-align: justify\">\u00a0<strong>Filtering condition <\/strong>&#8211; checked when the triggering event occurs<strong> (C)<\/strong><\/li>\n<li style=\"text-align: justify\">\u00a0<strong>Target <\/strong>&#8211; table (or view) against which the trigger is fired; they should be both created within the same schema<\/li>\n<li style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span><strong style=\"text-align: initial;font-size: 1em\">Trigger Parameters <\/strong><span style=\"text-align: initial;font-size: 1em\">&#8211; parameters used to denote the record columns; preceded by colon<\/span><strong style=\"text-align: initial;font-size: 1em\">:new, :old for new and old versions of the values respectively<\/strong><\/li>\n<li style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0Trigger action <\/strong><span style=\"text-align: initial;font-size: 1em\">&#8211; SQL statements, executed when the trigger fires; surrounded by <\/span><strong style=\"text-align: initial;font-size: 1em\">Begin<\/strong><span style=\"text-align: initial;font-size: 1em\"> &#8230; <\/span><strong style=\"text-align: initial;font-size: 1em\">End (A)\u00a0\u00a0<\/strong><\/li>\n<\/ul>\n<\/div>\n<div style=\"text-align: justify\">\n<p>\u00a0 CREATE [OR REPLACE] TRIGGER <em>trigger_name<\/em><\/p>\n<p><em>timing event1 [<\/em>OR<em> event2 <\/em>OR<em> event3] <\/em>ON <em>table_name<\/em><\/p>\n<p>BEGIN<\/p>\n<p><em>SQL statements;<\/em><\/p>\n<p>END;<\/p>\n<\/div>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0The trigger body consisting of <\/span><em style=\"text-align: initial;font-size: 1em\">SQL statements<\/em><span style=\"text-align: initial;font-size: 1em\"> will be executed only <\/span><strong style=\"text-align: initial;font-size: 1em\"><em>once <\/em><\/strong><span style=\"text-align: initial;font-size: 1em\">according to the prescribed <\/span><em style=\"text-align: initial;font-size: 1em\">timing<\/em><span style=\"text-align: initial;font-size: 1em\">, when the <\/span><em style=\"text-align: initial;font-size: 1em\">event1 (event2, event3) <\/em><span style=\"text-align: initial;font-size: 1em\">occurs against the monitored table in question<\/span><em style=\"text-align: initial;font-size: 1em\"> table_name.<\/em><\/p>\n<p><em>\u00a0<\/em><\/p>\n<div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-232 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110.png\" alt=\"\" width=\"645\" height=\"366\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110.png 578w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110-300x170.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110-65x37.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110-225x128.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-110-350x199.png 350w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 Syntax for Creating Row Triggers<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>CREATE [OR REPLACE] TRIGGER <em>trigger_name<\/em><\/p>\n<p><em>timing event1 [<\/em>OR<em> event2 <\/em>OR<em> event3] <\/em>ON <em>table_name<\/em><\/p>\n<p>[REFERENCING OLD AS <em>old |<\/em> NEW AS <em>new<\/em>]<\/p>\n<p>FOR EACH ROW<\/p>\n<p>[WHEN <em>condition<\/em>]<\/p>\n<p>BEGIN<\/p>\n<p><em>SQL statements;<\/em><\/p>\n<p>END<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The trigger body consisting of <em>SQL statements<\/em> will be executed once <strong><em>for each row<\/em><\/strong> affected by <em>event1<\/em> (<em>event2<\/em>, <em>event3<\/em>) in the table named <em>table_name<\/em> subject to the additional <em>condition<\/em>.<\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0 SQL&gt;CREATE OR REPLACE TRIGGER derive_commission_trg <\/strong><\/p>\n<p><strong>2 BEFORE UPDATE OF sal ON emp<\/strong><\/p>\n<p><strong>3 FOR EACH ROW\u00a0<\/strong><\/p>\n<p><strong>4 WHEN (new.job = &#8216;SALESMAN&#8217;)<\/strong><\/p>\n<p><strong>5\u00a0 <\/strong><strong>BEGIN<\/strong><\/p>\n<p><strong>6\u00a0\u00a0<\/strong><strong>:new.comm := :old.comm * (:new.sal\/:old.sal);<\/strong><\/p>\n<p><strong>\u00a0<\/strong><strong>7\u00a0 <\/strong><strong>END;<\/strong><\/p>\n<p><strong>8\u00a0<\/strong><\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-233 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111.png\" alt=\"\" width=\"549\" height=\"194\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111.png 498w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111-300x106.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111-65x23.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111-225x80.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-111-350x124.png 350w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Trigger Execution Order<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0\u00a0\u00a0 Execute all BEFORE STATEMENT triggers.<\/p>\n<p>2.\u00a0\u00a0\u00a0 Disable temporarily all integrity constraints recorded against the table.<\/p>\n<p>3.\u00a0\u00a0\u00a0 Loop for each row in the table.<\/p>\n<ul>\n<li>\u00a0 Execute all BEFORE ROW triggers.<\/li>\n<li>\u00a0 Execute the SQL statement against the row and perform integrity constraint checking of the data.<\/li>\n<li>\u00a0 Execute all AFTER ROW triggers.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>4. Complete deferred integrity constraint checking against the table.<\/p>\n<p>5. Execute all AFTER STATEMENT triggers.<\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Controlling Triggers using SQL<\/span><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 Disable\/Re-enable database trigger<\/strong><\/p>\n<p>ALTER TRIGGER trigger_name\u00a0 DISABLE | ENABLE<\/p>\n<p><strong>Disable or Re-enable all triggers for table<\/strong><\/p>\n<p>ALTER TABLE <em>table_name DISABLE<\/em> | <em>ENABLE<\/em> ALL TRIGGERS<\/p>\n<p><strong>Removing a trigger from database<\/strong><\/p>\n<p>DROP TRIGGER trigger_name<\/p>\n<\/div>\n<p><strong><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0Using Database Triggers<\/span><\/strong><\/p>\n<div>\n<p>\u00a0 \u00a0 \u00a0\u00a0<strong>Auditing Table Operations<\/strong><\/p>\n<p>each time a table is accessed auditing information is recorded against it<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Tracking Record Value Changes<\/strong><\/p>\n<p>each time a record value is changed the previous value is recorded<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Protecting Database Referential Integrity: <\/strong>if foreign key points to changing records<\/p>\n<p>referential integrity must be maintained<\/p>\n<\/div>\n<div>\n<p><strong>\u00a0 \u00a0 Maintenance of Semantic Integrity<\/strong><\/p>\n<p><strong>e.g. <\/strong>when the factory is closed, all employees should become unemployed<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Storing Derived Data<\/strong><\/p>\n<p><strong>\u00a0e.g. <\/strong>the number of items in the trolley should correspond to the current session selection<\/p>\n<p><strong>Security Access Control<\/strong><\/p>\n<p><strong>\u00a0e.g. <\/strong>checking user privileges when accessing sensitive information<\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0<strong>Counting Statement Execution<\/strong><\/span><\/p>\n<div>\n<p><strong>\u00a0 \u00a0 SQL&gt;CREATE OR REPLACE TRIGGER audit_emp<\/strong><\/p>\n<p><strong>2 AFTER DELETE ON emp<\/strong><\/p>\n<p><strong>3 FOR EACH ROW<\/strong><\/p>\n<p><strong>4\u00a0 <\/strong><strong>BEGIN<\/strong><\/p>\n<p><strong>5\u00a0<\/strong><strong>UPDATE audit_table SET del = del + 1<\/strong><\/p>\n<p><strong>6\u00a0<\/strong><strong>WHERE user_name = USER<\/strong><\/p>\n<p><strong>7\u00a0<\/strong><strong>AND table_name = &#8216;EMP\u2019;<\/strong><\/p>\n<p><strong>7\u00a0 <\/strong><strong>END;<\/strong><\/p>\n<p><strong>8\u00a0 <\/strong><\/p>\n<\/div>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0Whenever an employee record is deleted from database, counter in an audit table registering the number of deleted rows for current user in system variable USER is incremented.<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span><\/p>\n<p><strong><span style=\"text-align: initial;font-size: 1em\">Recording Changes<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">SQL&gt;CREATE OR REPLACE TRIGGER audit_emp_values 2 AFTER DELETE OR UPDATE ON emp<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">3 FOR EACH ROW<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">4\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">BEGIN<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">5\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">INSERT INTO audit_emp_values (user_name,<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">6\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">timestamp, id, old_last_name, new_last_name,<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">7\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">old_title, new_title, old_salary, new_salary)<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">8\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">VALUES (USER, SYSDATE, :old.empno, :old.ename,<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">9\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">:new.ename, :old.job, :new.job,<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">10\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">:old.sal, :new.sal);<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">11\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">END;<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Whenever some details for an employee are deleted or updated, both the previous and new details are recorded in an audit table to allow tracing the history of changes. An insert operation cannot be recorded with this trigger as old.empno has no value.<\/p>\n<\/div>\n<div>\n<div>\n<p style=\"text-align: justify\"><strong><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 <\/span><\/strong><\/p>\n<p style=\"text-align: justify\"><strong><span style=\"text-align: initial;font-size: 1em\">Protecting Referential Integrity<\/span><\/strong><\/p>\n<\/div>\n<div>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0SQL&gt;CREATE OR REPLACE TRIGGER cascade_updates 2 AFTER UPDATE OF deptno ON dept<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a03 FOR EACH ROW<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">\u00a04\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">BEGIN<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">5\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">UPDATE emp<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">6<\/strong><span style=\"text-align: initial;font-size: 1em\">\u00a0\u00a0<\/span><strong style=\"text-align: initial;font-size: 1em\">SET<\/strong><span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span><strong style=\"text-align: initial;font-size: 1em\">emp.deptno = :new.deptno<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">7\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">WHERE\u00a0 emp.deptno = :old.deptno;<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">8\u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">END<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">9\u00a0\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">\/<\/strong><\/p>\n<\/div>\n<p style=\"text-align: justify\">\u00a0 \u00a0Whenever the department number changes, all employee records for this department will automatically be changed as well, so that the employees will continue to work for the same department.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong><span style=\"text-align: initial;font-size: 1em\">Restrictions for Database Triggers<\/span><\/strong><\/p>\n<\/div>\n<div>\n<p style=\"text-align: justify\"><strong>\u00a0 \u00a0 Problem: <\/strong>impossible to determine certain values during execution of a sequence of operations belonging to one and the same transaction.<\/p>\n<p style=\"text-align: justify\"><strong>Mutating tables: <\/strong>contain rows which change their values after certain operation and which are used again before the current transaction commits.<\/p>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">Preventing table mutation:<\/strong><\/p>\n<\/div>\n<div>\n<ul>\n<li>Should not contain rows which are constrained by rows from other changing tables<\/li>\n<li>Should not contain rows which are updated and read in one and the same operation<\/li>\n<li style=\"text-align: justify\">\u00a0Should not contain rows which are updated and read via other operations during the same transaction<\/li>\n<\/ul>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\"><strong>Mutating Table<\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>\u00a0 \u00a0 SQL&gt; CREATE OR REPLACE TRIGGER emp_count<\/strong><\/p>\n<p><strong>2\u00a0\u00a0\u00a0 <\/strong><strong>AFTER DELETE ON emp<\/strong><\/p>\n<p><strong>3\u00a0\u00a0\u00a0 <\/strong><strong>FOR EACH ROW<\/strong><\/p>\n<p><strong>4\u00a0\u00a0\u00a0 <\/strong><strong>DECLARE<\/strong><strong>\u00a0<\/strong><\/p>\n<p><strong>5\u00a0\u00a0\u00a0\u00a0<\/strong><strong>num INTEGER;<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">6\u00a0 \u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">BEGIN<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">7\u00a0 \u00a0\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">SELECT COUNT(*) INTO num FROM emp;<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">8\u00a0 \u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">DBMS_OUTPUT.PUT_LINE(&#8216; There are now &#8216; || num || &#8216; employees.&#8217;);<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">9\u00a0\u00a0\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">END;<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">10\u00a0\u00a0\u00a0 <\/strong><strong style=\"text-align: initial;font-size: 1em\">\/<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">SQL&gt; DELETE FROM emp<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">2\u00a0 WHERE\u00a0 deptno = 30;<\/strong><\/p>\n<div>\n<p><span style=\"text-align: justify;font-size: 1em\">\u00a0 \u00a0Under the bar is code entered in SQL-PLUS which triggers cascade_updates in this case. Triggers are not executed directly.<\/span><\/p>\n<\/div>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">Mutating Table (fixed)<\/span><\/p>\n<div>\n<p style=\"text-align: center\"><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-234\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112.png\" alt=\"\" width=\"843\" height=\"381\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112.png 843w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112-300x136.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112-768x347.png 768w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112-65x29.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112-225x102.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-112-350x158.png 350w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/strong><\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-235 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113.png\" alt=\"\" width=\"894\" height=\"448\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113.png 894w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113-300x150.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113-768x385.png 768w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113-65x33.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113-225x113.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-113-350x175.png 350w\" sizes=\"auto, (max-width: 894px) 100vw, 894px\" \/><\/p>\n<\/div>\n<p><strong>\u00a0 \u00a0 Rules for Good SQL Practice<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Rule 1:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>change data<\/em> in the primary key, foreign key, or unique key columns of any table.<\/p>\n<p><strong>Rule 2:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>update records<\/em> in the same table you read during the same transaction.<\/p>\n<p><strong>Rule 3:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>aggregate<\/em> over the same table you are updating.<\/p>\n<p><strong>Rule 4:<\/strong>\u00a0\u00a0\u00a0\u00a0 Do not <em>read data<\/em> from a table which is updated during the same transaction.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0 \u00a0 \u00a0SUMMARY<\/strong><\/p>\n<ul>\n<li>Active DBMSs embed situation-action rules in database.<\/li>\n<li>Support many functionalities:<\/li>\n<li>E.g.:\u00a0 Integrity control,access control,monitoring,derived data,change notification.<\/li>\n<li>Some Active DBMS functionality commercially available in SQL:99 as triggers.<\/li>\n<\/ul>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-236 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114.png\" alt=\"\" width=\"639\" height=\"360\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114.png 639w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114-300x169.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114-65x37.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114-225x127.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-114-350x197.png 350w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/p>\n","protected":false},"author":4,"menu_order":29,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-r-baskaran"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-230","chapter","type-chapter","status-publish","hentry","contributor-dr-r-baskaran"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":11,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/230\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/230\/revisions\/416"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/230\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapter-type?post=230"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/contributor?post=230"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/license?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}