1

I need to build a table accepting one row for each minute. If I set the type of primary key to datetime, 60 records can be added for each minute.

Is there any trick to design a table to keep 0000-00-00 00:00 unique?

3
  • Which version of MySQL ? Commented Dec 4, 2015 at 9:37
  • @ypercube 5.5 (more precise 5.5.35)
    – Googlebot
    Commented Dec 4, 2015 at 9:48
  • 1
    In 5.7 (and any MariaDB 5.3+ version) there are virtual columns that can be used for this. Commented Dec 4, 2015 at 10:00

1 Answer 1

2

Store CONCAT(LEFT(NOW(), 16), ':00') into the PRIMARY KEY that is a DATETIME.

mysql> SELECT NOW(), CONCAT(LEFT(NOW(), 16), ':00');
+---------------------+--------------------------------+
| NOW()               | CONCAT(LEFT(NOW(), 16), ':00') |
+---------------------+--------------------------------+
| 2015-12-11 21:37:38 | 2015-12-11 21:37:00            |
+---------------------+--------------------------------+

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.