Can I get a unique TIMESTAMP for every record in MySQL

前端 未结 2 1515
离开以前
离开以前 2020-12-17 05:00

Is there a possibility of getting a unique timestamp value for for each record in MySQL??..

I created a sample table

CREATE TABLE t1 (id int primar         


        
2条回答
  •  忘掉有多难
    2020-12-17 05:10

    Yes if you don't do two or more inserts or edits during one second. Only problem is that a lot stuff can be done during a second, i.e. multiple inserts or automatic updates using a where clause. That rules out the simple solution to force unique timestamps: to add unique constraint into timestamp column.

    Why should a timestamp be unique? Use auto increment or something else if you need unique index etc.

    If you need more precise time values than timestamp, see:

    • http://dev.mysql.com/doc/refman/5.5/en/fractional-seconds.html (Note: fractional part is discarded during insert. Not helping...)
    • http://codeigniter.com/forums/viewthread/66849/ (Apparently double(13,3) makes it possible to add microtime into DB.)
    • MySQL greater than problem with microtime timestamp (int multiplied with 100 or 1000 could also work. Here decimal is preferred over double.)
    • Why doesn't MySQL support millisecond / microsecond precision?

提交回复
热议问题