Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some day soon (5.6.4), MySQL will provide <a href="http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html" rel="noreferrer">fractional seconds</a> in TIMESTAMP columns, however, even fractional seconds aren't guaranteed to be unique, though theoretically, they'd most often be unique, especially if you limited MySQL to a single thread.</p> <p>You can use a <a href="http://dev.mysql.com/doc/refman/5.5/en/miscellaneous-functions.html#function_uuid" rel="noreferrer">UUID</a> if you need a unique number that is ordered temporally.</p> <p><code>SELECT UUID()</code> yields something like:</p> <pre><code>45f9b8d6-8f00-11e1-8920-842b2b55ce56 </code></pre> <p>And some time later:</p> <pre><code>004b721a-8f01-11e1-8920-842b2b55ce56 </code></pre> <p>The first three portions of a UUID consist of the time, however, they're in order from highest precision to least, so you'd need to reverse the first three portions using <code>SUBSTR()</code> and <code>CONCAT()</code> like this:</p> <pre><code>SELECT CONCAT(SUBSTR(UUID(), 15, 4), '-', SUBSTR(UUID(), 10, 4), '-', SUBSTR(UUID(), 1, 8)) </code></pre> <p>Yields:</p> <pre><code>11e1-8f00-45f9b8d6 </code></pre> <p>You obviously couldn't use a function like this as a default value, so you'd have to set it in code, but it's a guaranteed unique temporally ordered value. UUID() works at a much lower level than seconds (clock cycles), so it's guaranteed unique with each call and has low overhead (no locking like auto_increment).</p> <p>Using the UUID() on the database server may be preferred to using a similar function, such as PHP's <code>microtime()</code> function on the application server because your database server is more centralized. You may have more than one application (web) server, which may generate colliding values, and microtime() still doesn't guarantee unique values.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload