Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get id in 2012061000001 format
    primarykey
    data
    text
    <p>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</p> <pre><code>+----+------+-------------+---------+------------+-------------+ | id | vid | visitorname | company | contact | whometomeet | +----+------+-------------+---------+------------+-------------+ | 1 | NULL | rakesh | godrej | 9987654123 | abcdef | | 2 | NULL | samir | infosys | 9987654123 | abcdef | +----+------+-------------+---------+------------+-------------+ </code></pre> <p>how can we achieve this?</p> <p>here is my table structure where i set id as auto_increment can we have two fields auto_increment</p> <pre><code>+-------------+--------------+------+-----+---------+----------------+ | 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 | | +-------------+--------------+------+-----+---------+----------------+ </code></pre> <p>And firing folowing query i got result like below</p> <p>insert into visitor(vid)values(concat(replace(left(current_timestamp,10),'-',''),lpad('1','5','0')));</p> <pre><code>+----+---------------+-------------+---------+------------+-------------+ | id | vid | visitorname | company | contact | whometomeet | +----+---------------+-------------+---------+------------+-------------+ | 1 | NULL | rakesh | godrej | 9987654123 | abcdef | | 2 | NULL | samir | infosys | 9987654123 | abcdef | | 3 | 2012061000001 | NULL | NULL | NULL | NULL | +----+---------------+-------------+---------+------------+-------------+ </code></pre> <p>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.</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. 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