<?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: DEFAULT TIMESTAMP and UPDATE with no changes in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821493#M4852336</link>
    <description>&lt;P&gt;There is no option to change the behaviour of &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/817f7f716ce21014acd8ea0ef48bd43a.html*loio817f7f716ce21014acd8ea0ef48bd43a"&gt;DEFAULT TIMESTAMP&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Your alternative solution would be to change the column to be DEFAULT CURRENT TIMESTAMP and then write a BEFORE UPDATE trigger that checks if any of the values are being changed, and if yes then sets the timestamp column.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Oct 2015 10:05:00 GMT</pubDate>
    <dc:creator>MarkCulp</dc:creator>
    <dc:date>2015-10-20T10:05:00Z</dc:date>
    <item>
      <title>DEFAULT TIMESTAMP and UPDATE with no changes</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaq-p/13821492</link>
      <description>&lt;P&gt;Is there a database option or workaround that changed a column with default timestamp, only when a column in the row is really changed?&lt;/P&gt;
&lt;P&gt;For example:
UPDATE employees SET name = 'Mr. John' WHERE id = 1 ;
That update shows in a translated log, as expected and ok:
UPDATE name = 'Mr. John', my_timestamp_col = '2015-xxxxxxx...' WHERE id = 1 ;&lt;/P&gt;
&lt;P&gt;When the same SQL update is executed another time I see this in the translated log:
UPDATE my_timestamp_col = '2015-xxxxxxx...' WHERE id = 1 ;&lt;/P&gt;
&lt;P&gt;Because the row is not changed at all the timestamp should not be set.
Now we get a lot of updates that only set the timestamp column and a much more uncomitted rows.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 09:59:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaq-p/13821492</guid>
      <dc:creator>hansg</dc:creator>
      <dc:date>2015-10-20T09:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and UPDATE with no changes</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821493#M4852336</link>
      <description>&lt;P&gt;There is no option to change the behaviour of &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/817f7f716ce21014acd8ea0ef48bd43a.html*loio817f7f716ce21014acd8ea0ef48bd43a"&gt;DEFAULT TIMESTAMP&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Your alternative solution would be to change the column to be DEFAULT CURRENT TIMESTAMP and then write a BEFORE UPDATE trigger that checks if any of the values are being changed, and if yes then sets the timestamp column.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 10:05:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821493#M4852336</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2015-10-20T10:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and UPDATE with no changes</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821494#M4852337</link>
      <description>&lt;P&gt;Thanks!, we will think about it.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 10:07:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821494#M4852337</guid>
      <dc:creator>hansg</dc:creator>
      <dc:date>2015-10-20T10:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and UPDATE with no changes</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821495#M4852338</link>
      <description>&lt;P&gt;I guess you could also leave the default as DEFAULT TIMESTAMP and use a before update trigger to set the column to its previous value if all other (relevant) columns are left unchanged, something like&lt;/P&gt;
&lt;PRE&gt;   ...
   referencing old as o new as n
   for each row
   begin
      if     n.col1 is not distinct from o.col1
         and n.col2 is not distinct from o.col2
         and ...
         and n.colX is not distinct from o.colX
      then
         set n.my_timestamp_col = o.my_timestamp_col;
      end if;
   end;
&lt;/PRE&gt;

&lt;P&gt;That might be more fitting if you usually expect "real" updates (i.e. those that do modify data).&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 10:39:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821495#M4852338</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-10-20T10:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and UPDATE with no changes</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821496#M4852339</link>
      <description>&lt;P&gt;I had thought of this solution as an alternative but I'm not sure it will work - the server might set the timestamp column &lt;EM&gt;after&lt;/EM&gt; the trigger is executed. Some testing is required to check if this will work?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 10:44:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821496#M4852339</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2015-10-20T10:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and UPDATE with no changes</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821497#M4852340</link>
      <description>&lt;P&gt;Well, I agree, and I have not tested that (therefore my usage of "I guess you could..." and "something like").&lt;/P&gt;
&lt;P&gt;FWIW, several years ago, Glenn had given some detailed insights (as expected...) on the internal steps a trigger has to consider - cf. &lt;A href="http://nntp-archive.sybase.com/nntp-archive/action/article/%3C473cc78e%40forums-1-dub%3E"&gt;that old NNTP article "Before update trigger and computed column "&lt;/A&gt; - I'm not sure whether it is still true (well, I'm aware that something relevant has changed with computed columns in v11), however, according to Glenn's statements, normal defaults would be evaluated &lt;EM&gt;before&lt;/EM&gt; any triggers are called. I'm not sure whether DEFAULT TIMESTAMP counts as a normal default.&lt;/P&gt;
&lt;P&gt;So yes, some testing might be required:)&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 11:13:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-update-with-no-changes/qaa-p/13821497#M4852340</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-10-20T11:13:50Z</dc:date>
    </item>
  </channel>
</rss>

