<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: ALTER TABLE within trigger in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830201#M4861044</link>
    <description>&lt;P&gt;Based on Brecks great example here a solution with a Instead of trigger.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://dcx.sybase.com/index.html#1201/en/dbusage/proctrig-b-4949515.html"&gt;INSTEAD OF triggers&lt;/A&gt; differ from BEFORE and AFTER triggers because when an INSTEAD OF trigger fires, the triggering action is skipped and the specified action is performed instead.&lt;/P&gt;
&lt;PRE&gt;CREATE TABLE equipment_type (
   type            INTEGER NOT NULL PRIMARY KEY);

CREATE TABLE trained_on (
   id              INTEGER NOT NULL PRIMARY KEY,
   type            INTEGER NOT NULL,
   CONSTRAINT relationship_fixed_by 
      FOREIGN KEY ( type )  
      REFERENCES equipment_type );

CREATE TRIGGER updates_equipment_type
   INSTEAD OF INSERT ON trained_on
   REFERENCING NEW AS new_trained_on
   FOR EACH ROW
BEGIN
    INSERT INTO equipment_type on existing skip VALUES ( new_trained_on.type );
    INSERT INTO trained_on VALUES ( new_trained_on.id, new_trained_on.type );
END;

INSERT trained_on VALUES ( 1, 100 );
COMMIT;
INSERT trained_on VALUES ( 2, 100 );
COMMIT;
INSERT trained_on VALUES ( 3, 200 );
COMMIT;
INSERT trained_on VALUES ( 4, 200 );
COMMIT;

SELECT * FROM equipment_type;
SELECT * FROM trained_on;

type
100
200

id,type
1,100
2,100
3,200
4,200
&lt;/PRE&gt;

&lt;P&gt;I have left out the Constraint &lt;EM&gt;mandatory_participation_in_fixed_by&lt;/EM&gt; on the equipment type table is not possible with this solution.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jun 2012 06:39:47 GMT</pubDate>
    <dc:creator>thomas_duemesnil</dc:creator>
    <dc:date>2012-06-12T06:39:47Z</dc:date>
    <item>
      <title>ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaq-p/13830198</link>
      <description>&lt;P&gt;I am stuggling to create a trigger that drops a constraint using ALTER TABLE I have read that this command cannot be used within a trigger so have included it as a string.  All the code has been tested outside of a trigger and works correctly, any help would be appreciated.&lt;/P&gt;
&lt;P&gt;The error I am currently getting is 'commit rollback not alowed within atomic operation'&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TRIGGER&lt;/SPAN&gt; &lt;SPAN class="n"&gt;updates_equipment_type&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;BEFORE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;INSERT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ON&lt;/SPAN&gt; &lt;SPAN class="n"&gt;trained_on&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;REFERENCING&lt;/SPAN&gt;     &lt;SPAN class="n"&gt;NEW&lt;/SPAN&gt; &lt;SPAN class="n"&gt;AS&lt;/SPAN&gt; &lt;SPAN class="n"&gt;new_trained_on&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;FOR&lt;/SPAN&gt; &lt;SPAN class="n"&gt;EACH&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ROW&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;WHEN&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;new_trained_on&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;type&lt;/SPAN&gt; &lt;SPAN class="n"&gt;NOT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;IN&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;type&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="n"&gt;equipment_type&lt;/SPAN&gt;&lt;SPAN class="p"&gt;))&lt;/SPAN&gt;
    &lt;SPAN class="k"&gt;BEGIN&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;EXECUTE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;IMMEDIATE&lt;/SPAN&gt;       &lt;SPAN class="s"&gt;'ALTER TABLE trained_on&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            DROP CONSTRAINT relationship_fixed_by&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            ALTER TABLE equipment_type&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            DROP CONSTRAINT mandatory_participation_in_fixed_by'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
                            &lt;SPAN class="n"&gt;INSERT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;INTO&lt;/SPAN&gt; &lt;SPAN class="n"&gt;equipment_type&lt;/SPAN&gt;
                            &lt;SPAN class="n"&gt;VALUES&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;new_trained_on&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;type&lt;/SPAN&gt;&lt;SPAN class="p"&gt;);&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;EXECUTE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;IMMEDIATE&lt;/SPAN&gt;       &lt;SPAN class="s"&gt;'ALTER  TABLE trained_on&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            ADD CONSTRAINT relationship_fixed_by&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            FOREIGN KEY (type)&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            REFERENCES equipment_type&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            ALTER TABLE equipment_type&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            ADD CONSTRAINT mandatory_participation_in_fixed_by&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            CHECK (type IN (    SELECT type&lt;/SPAN&gt;
&lt;SPAN class="s"&gt;                            FROM trained_on))'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;

    &lt;SPAN class="k"&gt;END&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 11 Jun 2012 13:39:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaq-p/13830198</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-06-11T13:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830199#M4861042</link>
      <description>&lt;P&gt;Not being able to ALTER a table is not just a syntax issue, it is a semantic one: you cannot execute a COMMIT from within a trigger execution, and an ALTER implies a COMMIT. So, the EXECUTE IMMEDIATE does not help, it's still "within the trigger execution".
&lt;/P&gt;&lt;HR /&gt;
What you CAN do, if you don't necessarily want the ALTER to be performed right away, is to put the ALTER inside a CREATE EVENT, and then use TRIGGER EVENT to fire the event. An event runs asynchronously, on a separate connection, so it is a "fire and forget" kind of operation that doesn't cause problems for the "calling" connection.&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Do not confuse "TRIGGER EVENT" with CREATE TRIGGER, they don't have anything to do with one another. &lt;/P&gt;
&lt;P&gt;The CREATE EVENT needs a name, but no schedule or condition, because you are going to use an explicit TRIGGER EVENT.
&lt;/P&gt;&lt;HR /&gt;
In your case, you would have to move all the code into the event... as well as not caring that the event might not execute right away.&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 13:51:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830199#M4861042</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-06-11T13:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830200#M4861043</link>
      <description>&lt;P&gt;While I fully follow Breck's advice in general, in the current case, this won't work as expected IMHO:&lt;/P&gt;
&lt;P&gt;You seem to want to disable a CHECK constraint and a FOREIGN KEY constraint for the current table while entering "violating" data, so the desired solution to&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;drop the constraints,&lt;/LI&gt;
&lt;LI&gt;insert the missing data in the parent table and&lt;/LI&gt;
&lt;LI&gt;re-add the constraints&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;requires correct timing&lt;/STRONG&gt;, which won't be guaranteed with the asynchronous EVENT solution.&lt;/P&gt;
&lt;P&gt;There are possibly different approaches if you need to disable any logic during particular DML statements &lt;STRONG&gt;on a regular basis&lt;/STRONG&gt; - which would not require to ALTER TABLE in between (which will not scale very well, anyway, in case that might matter...).&lt;/P&gt;
&lt;P&gt;E.g. you might use a particular configuration table that can be used to disable checks for particular users or connections. Cf. &lt;A href="http://sqlanywhere-forum.sap.com/questions/389"&gt;this FAQ&lt;/A&gt; for a similar question on disabling trigger actions...&lt;/P&gt;
&lt;P&gt;We could surely give some sample code if you can elaborate what exactly you're trying to achieve. Ideas would include delayed foreign key checks with the "wait_for_commit" option (to add the missing parent entry "on demand") or a check including a CREATE VARIABLE to disable the check temporarily...&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 15:51:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830200#M4861043</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-11T15:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830204#M4861047</link>
      <description>&lt;P&gt;"requires correct timing" - that's why it says "you would have to move all the code into the event" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 16:24:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830204#M4861047</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-06-11T16:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830205#M4861048</link>
      <description>&lt;P&gt;OK, but would that not conflict with the INSERT statement itself?&lt;/P&gt;
&lt;P&gt;Re-reading the question, I would think that&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;using wait_for_commit and simply inserting the missing equipment_type entry during the insert into trained_on&lt;/LI&gt;
&lt;LI&gt;or even checking for missing parent entries before doing the insert&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;would be much simpler - but that's just my understanding of the question...&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 16:32:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830205#M4861048</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-11T16:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830206#M4861049</link>
      <description>&lt;P&gt;First of all, wait_for_commit doesn't affect the CHECK constraint that is dropped and added... if the CHECK is going to fail, it will still fail.&lt;/P&gt;
&lt;P&gt;Second of all, dropping and recreating a foreign key around a single INSERT seems pointless... if the INSERT causes a violation, the ALTER TABLE ADD foreign key will raise it. Generally, dropping and recreating foreign keys, or wait_for_commit, is ONLY useful if you have two or more operations... one which violates, and another which repairs the violation. That is not the case here, which implies the dropping and recreating the foreign key is pointless.&lt;/P&gt;
&lt;P&gt;I suspect more work needs to be done here... BUT, please tell me how moving all the code into an event would cause a conflict (or at least, a conflict that isn't already there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;...by "all code" I mean the four ALTERs and one INSERT.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 18:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830206#M4861049</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-06-11T18:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830207#M4861050</link>
      <description>&lt;P&gt;BTW, I am in agreement with your suggestion to "find another way".&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 18:09:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830207#M4861050</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-06-11T18:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830208#M4861051</link>
      <description>&lt;P&gt;Is this to get around having to separately manage equipment_types?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2012 19:23:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830208#M4861051</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-06-11T19:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830209#M4861052</link>
      <description>&lt;P&gt;Yes, "wait_for_commit" would not resolve the CHECK constraint issue - therefore I've hinted at a "check including a variable to disable the check temporarily...".&lt;/P&gt;
&lt;P&gt;The conflict might arise between the "INSERT trained_on ..." and the event code when triggered : &lt;/P&gt;
&lt;P&gt;Obviously we're dealing with an "INSERT trained_on ... " that tries to insert an equipment_type which does not already exist in the latter table.&lt;/P&gt;
&lt;P&gt;In that case the according FK constraint will fail, unless the FK is already dropped from within the event &lt;EM&gt;before&lt;/EM&gt; the INSERT statement is finished - or, in case "wait_for_commit" is set, before it is committed. That's the dangling timing issue I see. - In other words: I would think the event code must be run before the INSERT is finished, and that would not be guaranteed simply because of the asynchronous nature of event connections.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Correction: IMHO the ALTER TABLE &lt;STRONG&gt;cannot succeed timely&lt;/STRONG&gt;, as the following situation clearly would be satisfied:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"ALTER TABLE is prevented whenever the statement affects a table that is currently being used by another connection".&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 12 Jun 2012 03:43:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830209#M4861052</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-12T03:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830210#M4861053</link>
      <description>&lt;P&gt;Taking the check into the trigger code is surely more flexible (though usually less comprehensible, too, but that does not seem to matter here).&lt;/P&gt;
&lt;P&gt;However, I had the impression the insert should not fail in these cases but the missing parent record should be "fixed" - whereas a RAISERROR (or ROLLBACK TRIGGER, which I would prefer) would completely undo the insert, as well - at least unless the trigger contains according error-hanlding code.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2012 06:25:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830210#M4861053</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-12T06:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830201#M4861044</link>
      <description>&lt;P&gt;Based on Brecks great example here a solution with a Instead of trigger.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://dcx.sybase.com/index.html#1201/en/dbusage/proctrig-b-4949515.html"&gt;INSTEAD OF triggers&lt;/A&gt; differ from BEFORE and AFTER triggers because when an INSTEAD OF trigger fires, the triggering action is skipped and the specified action is performed instead.&lt;/P&gt;
&lt;PRE&gt;CREATE TABLE equipment_type (
   type            INTEGER NOT NULL PRIMARY KEY);

CREATE TABLE trained_on (
   id              INTEGER NOT NULL PRIMARY KEY,
   type            INTEGER NOT NULL,
   CONSTRAINT relationship_fixed_by 
      FOREIGN KEY ( type )  
      REFERENCES equipment_type );

CREATE TRIGGER updates_equipment_type
   INSTEAD OF INSERT ON trained_on
   REFERENCING NEW AS new_trained_on
   FOR EACH ROW
BEGIN
    INSERT INTO equipment_type on existing skip VALUES ( new_trained_on.type );
    INSERT INTO trained_on VALUES ( new_trained_on.id, new_trained_on.type );
END;

INSERT trained_on VALUES ( 1, 100 );
COMMIT;
INSERT trained_on VALUES ( 2, 100 );
COMMIT;
INSERT trained_on VALUES ( 3, 200 );
COMMIT;
INSERT trained_on VALUES ( 4, 200 );
COMMIT;

SELECT * FROM equipment_type;
SELECT * FROM trained_on;

type
100
200

id,type
1,100
2,100
3,200
4,200
&lt;/PRE&gt;

&lt;P&gt;I have left out the Constraint &lt;EM&gt;mandatory_participation_in_fixed_by&lt;/EM&gt; on the equipment type table is not possible with this solution.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2012 06:39:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830201#M4861044</guid>
      <dc:creator>thomas_duemesnil</dc:creator>
      <dc:date>2012-06-12T06:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830202#M4861045</link>
      <description>&lt;P&gt;Try this...&lt;/P&gt;
&lt;P&gt;Change the trigger to AFTER.&lt;/P&gt;
&lt;P&gt;Delete the EXECUTE IMMEDIATE ... ALTER TABLE statements, so only the INSERT equipment_type remains inside the trigger.&lt;/P&gt;
&lt;P&gt;Use SET TEMPORARY WAIT_FOR_COMMIT = 'ON' before your INSERT trained_on statements.&lt;/P&gt;
&lt;P&gt;Don't code INSERT equipment_type outside the trigger; let the trigger do it.&lt;/P&gt;
&lt;PRE&gt;CREATE TABLE equipment_type (
   type            INTEGER NOT NULL PRIMARY KEY,
   CONSTRAINT mandatory_participation_in_fixed_by 
      CHECK ( type IN ( SELECT type FROM trained_on ) ) );

CREATE TABLE trained_on (
   id              INTEGER NOT NULL PRIMARY KEY,
   type            INTEGER NOT NULL,
   CONSTRAINT relationship_fixed_by 
      FOREIGN KEY ( type )  
      REFERENCES equipment_type );

CREATE TRIGGER updates_equipment_type
   AFTER INSERT ON trained_on
   REFERENCING NEW AS new_trained_on
   FOR EACH ROW
   WHEN ( new_trained_on.type NOT IN ( SELECT type FROM equipment_type ) )
BEGIN
   INSERT INTO equipment_type  
      VALUES ( new_trained_on.type );
END;

SET TEMPORARY OPTION WAIT_FOR_COMMIT = 'ON';
INSERT trained_on VALUES ( 1, 100 );
COMMIT;
INSERT trained_on VALUES ( 2, 100 );
COMMIT;
INSERT trained_on VALUES ( 3, 200 );
COMMIT;
INSERT trained_on VALUES ( 4, 200 );
COMMIT;
SET TEMPORARY OPTION WAIT_FOR_COMMIT = 'OFF';

SELECT * FROM equipment_type;
SELECT * FROM trained_on;

type
100
200

id,type
1,100
2,100
3,200
4,200
&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jun 2012 10:20:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830202#M4861045</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-06-12T10:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830211#M4861054</link>
      <description>&lt;P&gt;Ah, yes, well... I offer a money-back guarantee on all my free advice!&lt;/P&gt;
&lt;P&gt;...perhaps my second reply will serve as penance?&lt;/P&gt;
&lt;P&gt;&lt;IMG alt="alt text" src="http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/10000/7000/000/17097/17097.strip.sunday.gif" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2012 10:24:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830211#M4861054</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-06-12T10:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830212#M4861055</link>
      <description>&lt;P&gt;"Wow - surely better" than all other replies so far!&lt;/P&gt;
&lt;P&gt;And it's even real code:)&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;BTW: Instead of the "wait_on_commit" option, one might also declare  the FK with the &lt;STRONG&gt;CHECK ON COMMIT clause&lt;/STRONG&gt;, in case the "automatic type addition" should work always and not only when that particular option is set:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;  &lt;SPAN class="p"&gt;...&lt;/SPAN&gt;
  &lt;SPAN class="k"&gt;FOREIGN&lt;/SPAN&gt; &lt;SPAN class="k"&gt;KEY&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="k"&gt;type&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt;    
  &lt;SPAN class="k"&gt;REFERENCES&lt;/SPAN&gt; &lt;SPAN class="n"&gt;equipment_type&lt;/SPAN&gt;
  &lt;SPAN class="k"&gt;CHECK&lt;/SPAN&gt; &lt;SPAN class="k"&gt;ON&lt;/SPAN&gt; &lt;SPAN class="k"&gt;COMMIT&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 Jun 2012 10:41:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830212#M4861055</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-12T10:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830203#M4861046</link>
      <description>&lt;P&gt;Thanks very much for taking the time to write such detailed replies, It has been a great help.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2012 14:48:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830203#M4861046</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-06-12T14:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830213#M4861056</link>
      <description>&lt;P&gt;In case any answer is preferrable from your point of, feel free to accept that one - cf. &lt;A href="http://sqlanywhere-forum.sap.com/questions/7748"&gt;this little HOWTO&lt;/A&gt;...&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2012 14:54:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830213#M4861056</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-12T14:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830214#M4861057</link>
      <description>&lt;P&gt;An interesting approach - I surely stumbled on the recursive part (the instead of trigger on trained_on does itself insert into that table), but the docs truly allow that (i.e. prevent a recursive calling) for base tables:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Whether an INSTEAD OF trigger performs recursion depends on whether the target of the trigger is a base table or a view. Recursion occurs for views, but not for base tables. That is, if an INSTEAD OF trigger performs DML operations on the base table on which the trigger is defined, those operations do not cause triggers to fire (including BEFORE or AFTER triggers). If the target is a view, all triggers fire for the operations performed on the view.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 13 Jun 2012 07:20:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830214#M4861057</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-13T07:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: ALTER TABLE within trigger</title>
      <link>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830215#M4861058</link>
      <description>&lt;P&gt;And Breck has summed up the whole story of this nice thread in his blog:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlanywhere.blogspot.de/2012/06/back-up-start-over-find-another-way.html"&gt;Back up, start over, find another way&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;An "act of penance" worth reading, methinks:)&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 03:38:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/alter-table-within-trigger/qaa-p/13830215#M4861058</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-06-15T03:38:25Z</dc:date>
    </item>
  </channel>
</rss>

