List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 7 2001 9:12pm
Subject:Re: Zerofill Auto_Increment
View as plain text  
At 1:25 PM -0500 8/7/01, mickalo@stripped wrote:
>Hi All,
>Not sure if this is a bug or just a standard behavior of a auto_increment
>zerofill column.
>I have a column in a MySQL database table assigned as such:
>memid int(8) auto_increment zerofill primary key,
>now when the a new row is inserted in fills the column with the 
>appropriate 0's,
>but when I do a 'SELECT LAST_INSERT_ID()', after the insert, I get the last
>insert number, without the zeros, IE... Last inserted id value = 
>'00000012' but
>the return value is '12' and if I do a SELECT * FROM table_name WHERE memid =
>'12'; or SELECT * FROM table_name WHERE memid = '00000012';
>I get the same results, whether I use '12' or '00000012'
>Is this suppose to do that?? Just curious :)

LAST_INSERT_ID() returns a function value, not a table column value.
To get the result you want, you could use LPAD(LAST_INSERT_ID(),8,'0').

Paul DuBois, paul@stripped
Zerofill Auto_Incrementmickalo7 Aug
  • Re: Zerofill Auto_IncrementPaul DuBois7 Aug
    • Re: Zerofill Auto_Incrementmickalo8 Aug