Unix Technical Forum

adding record w ID=0

This is a discussion on adding record w ID=0 within the MySQL forums, part of the Database Server Software category; --> I have an already existing table created w auto-increment (starting : 1) I need to add a record w ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:04 AM
Josselin
 
Posts: n/a
Default adding record w ID=0

I have an already existing table created w auto-increment (starting : 1)
I need to add a record w ID=0 manually...
I tried to do it w phpmyadmin... but I always get a new record w the
last increment value +1 never the 0...
how can I do it manually ?

thanks for your help ..

joss

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:04 AM
strawberry
 
Posts: n/a
Default Re: adding record w ID=0

On Jun 20, 6:03 am, Josselin <josse...@wanadoo.fr> wrote:
> I have an already existing table created w auto-increment (starting : 1)
> I need to add a record w ID=0 manually...
> I tried to do it w phpmyadmin... but I always get a new record w the
> last increment value +1 never the 0...
> how can I do it manually ?
>
> thanks for your help ..
>
> joss


You can't.

You can alter the table...

ALTER TABLE `my_table` CHANGE `id` `id` TINYINT( 4 ) NOT NULL

....and then insert your 0 value...

INSERT INTO `my_table` (id) VALUES (0)

....but when you revert the structure...

ALTER TABLE `id` CHANGE `id` `id` TINYINT( 4 ) NOT NULL
AUTO_INCREMENT

....the table will renumber itself from 1!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:04 AM
Josselin
 
Posts: n/a
Default Re: adding record w ID=0

On 2007-06-20 14:48:07 +0200, strawberry <zac.carey@gmail.com> said:

> On Jun 20, 6:03 am, Josselin <josse...@wanadoo.fr> wrote:
>> I have an already existing table created w auto-increment (starting : 1)
>> I need to add a record w ID=0 manually...
>> I tried to do it w phpmyadmin... but I always get a new record w the
>> last increment value +1 never the 0...
>> how can I do it manually ?
>>
>> thanks for your help ..
>>
>> joss

>
> You can't.
>
> You can alter the table...
>
> ALTER TABLE `my_table` CHANGE `id` `id` TINYINT( 4 ) NOT NULL
>
> ...and then insert your 0 value...
>
> INSERT INTO `my_table` (id) VALUES (0)
>
> ...but when you revert the structure...
>
> ALTER TABLE `id` CHANGE `id` `id` TINYINT( 4 ) NOT NULL
> AUTO_INCREMENT
>
> ...the table will renumber itself from 1!


OK thanks.. maybe creating a new table with increment starting at 0
then importaing all data and renaming the table ...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 10:04 AM
strawberry
 
Posts: n/a
Default Re: adding record w ID=0

On Jun 22, 6:43 am, Josselin <josse...@wanadoo.fr> wrote:
> On 2007-06-20 14:48:07 +0200, strawberry <zac.ca...@gmail.com> said:
>
>
>
> > On Jun 20, 6:03 am, Josselin <josse...@wanadoo.fr> wrote:
> >> I have an already existing table created w auto-increment (starting : 1)
> >> I need to add a record w ID=0 manually...
> >> I tried to do it w phpmyadmin... but I always get a new record w the
> >> last increment value +1 never the 0...
> >> how can I do it manually ?

>
> >> thanks for your help ..

>
> >> joss

>
> > You can't.

>
> > You can alter the table...

>
> > ALTER TABLE `my_table` CHANGE `id` `id` TINYINT( 4 ) NOT NULL

>
> > ...and then insert your 0 value...

>
> > INSERT INTO `my_table` (id) VALUES (0)

>
> > ...but when you revert the structure...

>
> > ALTER TABLE `id` CHANGE `id` `id` TINYINT( 4 ) NOT NULL
> > AUTO_INCREMENT

>
> > ...the table will renumber itself from 1!

>
> OK thanks.. maybe creating a new table with increment starting at 0
> then importaing all data and renaming the table ...


Or just add a 'my_id' column with a value 1 less than the id coulmn -
or just SELECT id -1 FROM my_table

Why do you need to start at 0 anyway?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:50 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com