Set AUTO_INCREMENT format as "date / Num"

These are my first questions, so please forgive me for any mistakes .....

What I want to do is set the Auto_increment parameter in the MySQL database so that it starts counting from a specific format, for example:

date / date

for example: 2011-06-01 / 0001, 2011-06-01 / 0002,,,, 2011-06-02 / 0001, 2011-06-02 / 0002

        ...and so on

I hope that I will make my problem understandable, and thanks in advance .........

+3
source share
3 answers

, . INSERT. MySQL , , , , . , , .

0

create table test (
id int(4) zerofill auto_increment,
mydate date,
primary key (mydate,id)
);

insert into test (mydate) 
values 
('2011-06-01'),
('2011-06-02'),
('2011-06-02'),
('2011-06-01'),
('2011-06-01'),
('2011-06-03');



mysql> select * from test;
+------+------------+
| id   | mydate     |
+------+------------+
| 0001 | 2011-06-01 |
| 0002 | 2011-06-01 |
| 0003 | 2011-06-01 |
| 0001 | 2011-06-02 |
| 0002 | 2011-06-02 |
| 0001 | 2011-06-03 |
+------+------------+
6 rows in set (0.00 sec)
0

Microsecond timestamp? as

CREATE table t (
    f1 TIMESTAMP(6) DEFAULT CURRENT_DATETIME
);

and select the numbered line:

SET @rownum : = 0
SELECT @rownum := @rownum + 1 AS num, t.*
  FROM t
 WHERE DATE(t.f1) = '2011-01-01'
0
source

All Articles