I have following table structure there is column vid in that i want entry todays date followed by 00001 like ‘2012061000001’and when next time table get updated vid should be ‘20120610000002’
when if tommorow table will get update then vid should be 2012061100003
+----+------+-------------+---------+------------+-------------+
| id | vid | visitorname | company | contact | whometomeet |
+----+------+-------------+---------+------------+-------------+
| 1 | NULL | rakesh | godrej | 9987654123 | abcdef |
| 2 | NULL | samir | infosys | 9987654123 | abcdef |
+----+------+-------------+---------+------------+-------------+
how can we achieve this?
here is my table structure where i set id as auto_increment can we have two fields auto_increment
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| vid | varchar(15) | YES | | NULL | |
| visitorname | varchar(255) | YES | | NULL | |
| company | varchar(255) | YES | | NULL | |
| contact | varchar(30) | YES | | NULL | |
| whometomeet | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
And firing folowing query i got result like below
insert into visitor(vid)values(concat(replace(left(current_timestamp,10),’-‘,”),lpad(‘1′,’5′,’0’)));
+----+---------------+-------------+---------+------------+-------------+
| id | vid | visitorname | company | contact | whometomeet |
+----+---------------+-------------+---------+------------+-------------+
| 1 | NULL | rakesh | godrej | 9987654123 | abcdef |
| 2 | NULL | samir | infosys | 9987654123 | abcdef |
| 3 | 2012061000001 | NULL | NULL | NULL | NULL |
+----+---------------+-------------+---------+------------+-------------+
but problem is each time i will get that 1 there in vid if tommorow also i run this query i willl get tommorow date but that would be followed by that 00001 i want it 00002.
I’d suggest you don’t want to combine columns like that – it makes running queries relating to those fields a real pain (i.e. inefficient…)
Instead, have a
datecolumn and anvidcolumn. e.g.Then you can select on events on a given date.
Depending upon what your use case is, you could even make
vidanAUTO_INCREMENT. (Although at that point, it’s hard to tell the difference betweenidandvid.)