<?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 system clock in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826348#M4857191</link>
    <description>&lt;P&gt;Well, DEFAULT TIMESTAMP does seem to behave differently.&lt;/P&gt;
&lt;P&gt;And now one might ask whether a table with both a DEFAULT CURRENT TIMESTAMP and a DEFAULT TIMESTAMP (for "dtAdded" and "dtLastChanged" values) will have totally different values for newly inserted rows when the system-clock has been set backward in-between...&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2013 07:43:37 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2013-10-09T07:43:37Z</dc:date>
    <item>
      <title>DEFAULT TIMESTAMP and system clock</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaq-p/13826343</link>
      <description>&lt;P&gt;From the documentation&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Columns declared with DEFAULT TIMESTAMP contain unique values so that applications can detect near-simultaneous updates to the same row. If the present timestamp value is the same as the last value, it is incremented by the value of the default_timestamp_increment option.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This all sounds reasonable, but what happens if the system clock is changed (for example set back due to a time server synchronization). Can this cause a situation where either &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;DEFAULT TIMESTAMP gives a value less than its previous value or worse&lt;/LI&gt;
&lt;LI&gt;DEFAULT TIMESTAMP returns a value that is non-unique&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This seems possible given the last sentence suggests that it is only compared against the previous value, so if the DEFAULT TIMESTAMP value does go backwards due to a clock change, it could conceivably produce the same value twice.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2013 19:34:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaq-p/13826343</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-10-08T19:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and system clock</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826344#M4857187</link>
      <description>&lt;P&gt;If you want something unique from the database system use an autoincrement field or a GUID field. Or you can force uniqness of the timestamp field by declaring a unique index on it (anyway this may reject otherwise valid inserts &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; ). Doing so would at least identify a system clock problem.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2013 02:57:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826344#M4857187</guid>
      <dc:creator>MCMartin</dc:creator>
      <dc:date>2013-10-09T02:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and system clock</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826345#M4857188</link>
      <description>&lt;P&gt;Well, according to some tests with 12.0.1.3942, the database engine seems to make sure that DEFAULT TIMESTAMP values are increasing monotonically - as long as the database engine is running.&lt;/P&gt;
&lt;P&gt;I.e. when using a local database engine and modifying the system clock, it seems that&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;setting the system clock forward (say, to tomorrow) makes DEFAULT TIMESTAMP use the new (later) value&lt;/LI&gt;
&lt;LI&gt;setting the system clock backward (say, to yesterday) makes DEFAULT TIMESTAMP ignore the new (former) value and continue to use the current values - increased as usual by the value of the "default_timestamp_increment" option.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In contrast, SELECT GETDATE() will always return the system time: When the system clock is set back to yesterday, it will display that. Therefore DEFAULT TIMESTAMP may be ahead of the system time... &lt;/P&gt;
&lt;P&gt;However, when the engine is shutdown and restarted after the system clock has been set to a former time, it will happily use that system time for new DEFAULT TIMESTAMP values. &lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;Given that, I would think that &lt;STRONG&gt;DEFAULT TIMESTAMP does protect a running system against decreasing values&lt;/STRONG&gt; but does not guarantee that when the engine (or only the database?) is shutdown in-between.&lt;/P&gt;
&lt;P&gt;If you are primarily worried over influences of time synchronization, then I would think that this should not be a problem:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;For a running database engine, the engine seems to protect accordingly.&lt;/LI&gt;
&lt;LI&gt;For a server restart, I would suspect that stopping and re-starting will usually take much longer than the usual timespans that are added/subtracted due to synchronization.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Just a switch between standard time and daylight saving time might need particular care - if so, feel free to use DEFAULT UTC TIMESTAMP:)&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2013 07:20:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826345#M4857188</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-10-09T07:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and system clock</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826347#M4857190</link>
      <description>&lt;P&gt;Conclusion: Except for the (extremly rare) case that you would&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;stop the database engine,&lt;/LI&gt;
&lt;LI&gt;set back the clock to a former time,&lt;/LI&gt;
&lt;LI&gt;restart the engine and&lt;/LI&gt;
&lt;LI&gt;insert/update a row exactly at a datetime that is equal (on a micro-second base!) to a datetime that has been used before,&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I would think you can expect these values to be UNIQUE. (And note: Even GUIDs are not truly guaranteed to be unique).&lt;/P&gt;
&lt;P&gt;In order to &lt;STRONG&gt;make sure&lt;/STRONG&gt; these values are unique, I would second Martin's suggestion to use an explicit UNIQUE KEY or UNIQUE INDEX. And obviously, a constraint or trigger could be used to make sure that values must be increasing - though that might be an expensive check for huge tables.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2013 07:28:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826347#M4857190</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-10-09T07:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and system clock</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826346#M4857189</link>
      <description>&lt;P&gt;&lt;A href="http://sqlanywhere.blogspot.ca/2011/07/beware-current-timestamp.html"&gt;Beware CURRENT TIMESTAMP&lt;/A&gt;! ( your computer can travel in time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2013 07:38:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826346#M4857189</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2013-10-09T07:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: DEFAULT TIMESTAMP and system clock</title>
      <link>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826348#M4857191</link>
      <description>&lt;P&gt;Well, DEFAULT TIMESTAMP does seem to behave differently.&lt;/P&gt;
&lt;P&gt;And now one might ask whether a table with both a DEFAULT CURRENT TIMESTAMP and a DEFAULT TIMESTAMP (for "dtAdded" and "dtLastChanged" values) will have totally different values for newly inserted rows when the system-clock has been set backward in-between...&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2013 07:43:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/default-timestamp-and-system-clock/qaa-p/13826348#M4857191</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-10-09T07:43:37Z</dc:date>
    </item>
  </channel>
</rss>

