Page 1 of 1

Tables & IDs

Posted: Sun Dec 10, 2006 4:51 am
by Subfusion
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've got a table which has an ID field and it automatically increments. When incrementing it incriments in the following order: 1, 2, 3, 4, 5; I would like my IDs to start in this order: 0001, 0002, 0003, 0004, 0005. 

How can I achieve this?

This is my table structure:
[syntax="sql"]
CREATE TABLE `orders` (
  `id` int(5) NOT NULL auto_increment,
  `name` text NOT NULL,
  `email` text NOT NULL,
  `website` text NOT NULL,
  `notes` longtext NOT NULL,
  `subpages` int(11) NOT NULL default '0',
  `integration` text NOT NULL,
  `template` text NOT NULL,
  `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `status` int(11) NOT NULL default '0',
  `key` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: Tables & IDs

Posted: Sun Dec 10, 2006 7:39 am
by hrubos
Subfusion wrote:I've got a table which has an ID field and it automatically increments. When incrementing it incriments in the following order: 1, 2, 3, 4, 5; I would like my IDs to start in this order: 0001, 0002, 0003, 0004, 0005.

How can I achieve this?

This is my table structure:

Code: Select all

CREATE TABLE `orders` (
  `id` int(5) NOT NULL auto_increment,
  `name` text NOT NULL,
  `email` text NOT NULL,
  `website` text NOT NULL,
  `notes` longtext NOT NULL,
  `subpages` int(11) NOT NULL default '0',
  `integration` text NOT NULL,
  `template` text NOT NULL,
  `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `status` int(11) NOT NULL default '0',
  `key` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I haven't try this way but I thing it can be. so you insert the first vaule is 0001, and too choose autoincrement. Try it

Posted: Sun Dec 10, 2006 8:27 am
by feyd
Set the field to ZERO FILL.

Posted: Sun Dec 10, 2006 10:43 pm
by neel_basu
ya zero Field is What You Want

Posted: Mon Dec 11, 2006 12:56 am
by dibyendrah
feyd wrote:Set the field to ZERO FILL.
How can we achieve this ZERO FILL? Will you please explain more about this ?
Thank you.

Posted: Mon Dec 11, 2006 12:59 am
by feyd
It's a field attribute similar to "NOT NULL"

Posted: Mon Dec 11, 2006 1:43 am
by volka
and it's an mysql specific extension to the sql standard and
http://dev.mysql.com/doc/refman/5.1/en/numeric-type-overview.html wrote:If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.
It's not a bad thing, just to remember.