<?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: Foreign key recursive (into same table) appears to require CHECK ON COMMIT in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849443#M4880286</link>
    <description>&lt;P&gt;Thanks I am checking.  My problem there is a second recursion on the same column I missed; it should work when filled in.  Sorry I was too tricky for my own good on this design.&lt;/P&gt;</description>
    <pubDate>Sun, 25 Nov 2018 14:40:58 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2018-11-25T14:40:58Z</dc:date>
    <item>
      <title>Foreign key recursive (into same table) appears to require CHECK ON COMMIT</title>
      <link>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaq-p/13849440</link>
      <description>&lt;P&gt;Using SQLAnywhere Developer v16 (I believe this observation is valid)&lt;/P&gt;
&lt;P&gt;if a table contains columns id, idParent, Name&lt;/P&gt;
&lt;P&gt;PK is id and FK between idParent (child) and id (parent) is established for the table&lt;/P&gt;
&lt;P&gt;INSERT INTO table ( id, idParent, Name )
       VALUES     ( 0, 0, 'none');&lt;/P&gt;
&lt;P&gt;appears to require the recursive foreign key relationship between id and idParent 
       to be coded with CHECK ON COMMIT&lt;/P&gt;
&lt;P&gt;Probably because the PK index for ID has not been updated 
      for the row being added when the foreign key is checked.&lt;/P&gt;
&lt;P&gt;QUESTION: Should the foreign key logic test for the special recursive relationship 
      where id = idParent on insertion of a row so CHECK ON COMMIT is not required?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 10:01:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaq-p/13849440</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-11-20T10:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Foreign key recursive (into same table) appears to require CHECK ON COMMIT</title>
      <link>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849441#M4880284</link>
      <description>&lt;P&gt;I have used tables with self-references from SQL Anywhere 5.5 to 17 and have never needed to use the CHECK ON COMMIT clause, and the wait_for_commit option has usually not been set to 'On'.&lt;/P&gt;
&lt;P&gt;I don't remember that cases with insertions of a row that references itself in one go, i.e. where id and idParent are the same, led to problems.&lt;/P&gt;
&lt;P&gt;Here's a simple test, and I'm setting the DBISQL auto_commit to 'Off' to batch the inserts into one transaction:&lt;/P&gt;
&lt;PRE&gt;drop table if exists T_TestRI;
create table T_TestRI (
   id       int not null primary key,
   idParent int not null,
   someText varchar(30) not null,

   foreign key (idParent)
      references T_TestRI(id)
);
set option auto_commit = 'Off';
begin
   insert T_TestRI values (0, 0, 'self');
   insert T_TestRI values (1, 1, 'another self');
   insert T_TestRI values (2, 1, 'parent');
   insert T_TestRI values (3, 1, 'same parent');
   select connection_property('wait_for_commit');
end;
commit;
insert T_TestRI values (4, 6, 'unknown parent'); -- fails
 -- successful when transaction is allowed to continue after previous error
insert T_TestRI values (5, 5, 'yet another self');
commit;
select * from T_TestRI; -- lists entries with ids 0-3 and 5
commit;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Nov 2018 03:20:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849441#M4880284</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2018-11-21T03:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Foreign key recursive (into same table) appears to require CHECK ON COMMIT</title>
      <link>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849442#M4880285</link>
      <description>&lt;P&gt;Do you have a trigger on the insert?&lt;/P&gt;
&lt;P&gt;Sometimes "impossible" exceptions are caused by hidden code inside triggers... it is the &lt;STRONG&gt;first place to look&lt;/STRONG&gt; in those cases.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 09:17:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849442#M4880285</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2018-11-21T09:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Foreign key recursive (into same table) appears to require CHECK ON COMMIT</title>
      <link>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849443#M4880286</link>
      <description>&lt;P&gt;Thanks I am checking.  My problem there is a second recursion on the same column I missed; it should work when filled in.  Sorry I was too tricky for my own good on this design.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 14:40:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/foreign-key-recursive-into-same-table-appears-to-require-check-on-commit/qaa-p/13849443#M4880286</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-11-25T14:40:58Z</dc:date>
    </item>
  </channel>
</rss>

